- 博客(65)
- 资源 (1)
- 收藏
- 关注
原创 数据结构之插入排序
#include <iostream>using namespace std;void insertSort(int r[],int n){ int i,j; for(i=2;i<n;i++) { if(r[i]<r[i-1]) { r[0]=r[i]; //复制为哨兵 for(...
2018-06-30 11:44:10
336
原创 数据结构之选择排序
#include <iostream>using namespace std;void selectSort(int a[],int n){ for(int i=0;i<n;i++) { int k=i; for(int j=i+1;j<n;j++) { if(a[j] < a[k]) k=j; } if(k!=i) swap(a[k],a[i...
2018-06-30 11:29:55
310
原创 数据结构之冒泡排序
#include <iostream>using namespace std;void bubbleSort(int r[],int n){ for(int i=1;i<n-1;i++) { for(int j=1;j<n-i;j++) { if(r[j] > r[j+1]) swap(r[j],r[j+1]); } }}int main(){ int...
2018-06-30 11:22:29
355
原创 C++之重载矩阵相加
#include <iostream>using namespace std;class Matrix{ public: Matrix(); friend Matrix operator +(Matrix &,Matrix &); void input(); void display(); private: int mat[2][3]; };Matrix:...
2018-06-22 09:49:18
1727
原创 数据结构之采用邻接矩阵创建网,实现求双源最短路径的Floyd算法
#include <iostream>#include <iomanip>using namespace std;const int INF=99;const int n=4;int D[n][n]={ 0, 1,INF, 4, //Floyd算法的邻接矩阵,主对角线元素为0 INF, 0, 9, 2, ...
2018-06-18 13:14:12
403
原创 数据结构之采用邻接矩阵创建网,实现求单源最短路径的Dijkstra算法
#include <iostream>using namespace std;const int INF=9999;const int n=6; //顶点数int G[n][n]={INF,INF, 10,INF, 30,100, INF,INF, 5,INF,INF,INF, INF,INF,INF, 50,INF,INF, ...
2018-06-18 13:13:11
545
原创 数据结构之实现Kruskal算法,求连通图的最小生成树
#include <iostream>#include <algorithm>using namespace std;const int INF=99;const int n=6; //顶点数int G[n][n]={INF, 6, 1, 5,INF,INF, 6,INF, 5,INF, 3,INF, 1,...
2018-06-14 20:09:58
979
原创 数据结构之实现Prim算法,求连通图的最小生成树
#include <iostream>using namespace std;const int INF=99;const int n=6; //顶点数 int G[n][n]={INF, 6, 1, 5,INF,INF, 6,INF, 5,INF, 3,INF, 1, 5,INF, 5, 6, 4, ...
2018-06-14 20:06:59
2320
原创 数据结构之基于图的广度优先搜索,判断无向图的连通性
#include <iostream>using namespace std;struct LinkNode{ int data; LinkNode *next;};struct LinkQueue{ LinkNode *front; LinkNode *rear;};void init(LinkQueue *&Q){ Q=new LinkQueue; Q->front=...
2018-06-09 16:59:04
1225
原创 数据结构之实现无向图的广度优先搜索算法
#include <iostream>using namespace std;struct LinkNode{ int data; LinkNode *next;};struct LinkQueue{ LinkNode *front; LinkNode *rear;};void init(LinkQueue *&Q){ Q=new LinkQueue; Q->front=...
2018-06-09 16:52:44
741
原创 C++之重载流提取运算符
#include <iostream>using namespace std;class Complex { public: Complex() { real=0; imag=0; } Complex(double r,double i):real(r),imag(i){} friend istream & operator >>(istream ...
2018-06-08 10:10:33
1261
原创 C++之重载流插入运算符
#include <iostream>using namespace std;class Complex { public: Complex() { real=0; imag=0; } Complex(double r,double i):real(r),imag(i){} Complex operator +(Complex &); friend ostr...
2018-06-08 09:52:02
709
原创 C++之纯虚函数与抽象类
#include <iostream>using namespace std;class Shape{ public: virtual double area() const=0; };class Circle:public Shape //圆形 { public: Circle(double r):radius(r){} double area() const { ...
2018-06-08 09:27:42
215
原创 数据结构之基于深度优先搜索,输出无向图中给定的两个顶点之间的所有路径
#include <iostream>using namespace std;struct StackNode{ int data; StackNode *next;};void push(StackNode *&S,int e){ StackNode *p=new StackNode; p->data=e; p->next=S; S=p;}int pop(Stac...
2018-06-03 15:29:43
4186
原创 数据结构之实现图的深度优先搜索算法
#include <iostream>using namespace std;int G[10][10]={ {0,1,0,1,0}, {1,0,1,0,1}, {0,1,0,1,1}, {1,0,1,0,0}, {0,1,1,0,0}, }; int vexnum=5;int visited[5]...
2018-06-03 15:02:42
688
原创 C++之无向图3
#include <iostream>using namespace std;int G[10][10]={ {0,1,0,1,0}, {1,0,1,0,1}, {0,1,0,1,1}, {1,0,1,0,0}, {0,1,1,0,0}, };int vexnum=5;void show(){ for(int ...
2018-06-02 20:51:59
347
原创 C++之重载单目运算符2
#include <iostream>using namespace std;class Time{ public: Time() { minute=0; sec=0; } Time(int m,int s) { minute=m; sec=s; } Time operator ++ (); //声明前置自增运算符"++"重载函数 Time oper...
2018-06-02 16:22:20
325
原创 C++之重载单目运算符1
#include <iostream>using namespace std;class Time{ public: Time() { minute=0; sec=0; } Time(int m,int s) { minute=m; sec=s; } Time operator ++ (); void display() { cout<<...
2018-06-02 16:02:28
1946
原创 C++之运算符重载函数作为友元函数
#include <iostream>using namespace std;class Complex{ public: Complex() { real=0; imag=0; } Complex(double r,double i) { real=r; imag=i; } friend Complex operator + (Complex &...
2018-06-02 15:46:00
988
原创 C++之运算符的重载
#include <iostream>using namespace std;class Complex{ public: Complex() { real=0; imag=0; } Complex(double r,double i) { real=r; imag=i; } Complex operator + (Complex &c2); v...
2018-06-01 22:31:04
134
原创 C++之静态成员函数2
#include <iostream>using namespace std;class Student{ public: Student(int n,double s):num(n),score(s){} static double average(Student *,int); static void MaxScore(Student *,int); private: in...
2018-05-31 16:23:03
215
原创 C++之静态成员函数
#include <iostream>using namespace std;class Student{ public: Student(int n,int a,double s):num(n),age(a),score(s){} static double average(Student *stud,int); private: int num; int age; dou...
2018-05-31 15:59:19
159
原创 数据结构:无向图2
#include <iostream>using namespace std;int G[10][10]={ {0,1,0,1,0}, {1,0,1,0,1}, {0,1,0,1,1}, {1,0,1,0,0}, {0,1,1,0,0}, };int vexnum=5;void show(){ for(int i=0;i<vexnum;i++) { fo...
2018-05-30 13:26:59
283
原创 数据结构:无向图1
#include <iostream>using namespace std;int G[10][10]={ {0,1,0,1,0}, {1,0,1,0,1}, {0,1,0,1,1}, {1,0,1,0,0}, {0,1,1,0,0}, };int vexnum=5;void show(){ for(int i=0;i<vexnum;i++) { fo...
2018-05-30 12:27:13
766
原创 C++之虚基类
#include <iostream>using namespace std;class Person{ public: Person(string nam,string s,int a):name(nam),sex(s),age(a){} protected: string name; string sex; int age;};class Teacher:virtual p...
2018-05-30 11:23:27
165
原创 C++之多重继承派生类的构造函数
#include <iostream>using namespace std;class Teacher{ public: Teacher(string nam,int a,string t):name(nam),age(a),title(t){} void display() { cout<<"name:"<<name<<endl; ...
2018-05-30 11:01:19
1744
1
原创 C++之 友元成员函数
#include <iostream>using namespace std;class Date;class Time{ public: Time(int,int,int); void display(Date &); private: int hour; int minute; int sec;};class Date{ public: Date(int,int...
2018-05-25 10:09:02
424
原创 C++之将普通函数声明为友元函数
#include <iostream>using namespace std;class Time{ public: Time(int,int,int); friend void display(Time &); private: int hour; int minute; int sec;};Time::Time(int h,int m,int s){ hour=h...
2018-05-25 09:44:17
1402
原创 建立二叉排序树,并实现插入、查找等操作
#include <iostream>using namespace std;struct BSTNode{ int data; BSTNode *lchild; BSTNode *rchild;};void insertBST(BSTNode *&T,int e){ if(T) { if(e < T->data) insertBST(T-&...
2018-05-24 20:02:13
2927
原创 数据结构之判断给定的一棵二叉树是否是完全二叉树
#include <iostream>using namespace std;struct BitNode { char data; BitNode *lchild; BitNode *rchild;};struct LinkNode{ BitNode *data; LinkNode *next;};struct LinkQueue{ LinkNode *front; LinkNode...
2018-05-24 19:26:35
3189
原创 数据结构之判断两棵二叉树是否相等
#include <iostream>using namespace std;struct BitNode { char data; BitNode *lchild; BitNode *rchild; }; void create(BitNode *&T) { char ch; cin>>ch; if(ch=='#') T=N...
2018-05-20 15:34:18
7727
4
原创 C语言之多层派生时的构造函数
#include <iostream>using namespace std;class Student{ public: Student(int n,string nam) { num=n; name=nam; } void display1() { cout<<"num:"<<num<<endl; cout<<...
2018-05-19 16:27:02
435
原创 C语言之含有子对象的派生类的构造函数
#include <iostream>using namespace std;class Student{ public: Student(int n,string nam) { num=n; name=nam; } void display1() { cout<<"num:"<<num<<endl; cout<<...
2018-05-19 16:06:58
521
原创 C语言之派生类的析构函数
#include <iostream>using namespace std;class Student{ public: Student(int n,string nam) { num=n; name=nam; } ~Student() { cout<<"D."<<num<<endl; } protected: int n...
2018-05-19 15:57:45
826
原创 C语言之简单的派生类的构造函数
#include <iostream>using namespace std;class Student{ public: Student(int n,string nam) { num=n; name=nam; } protected: int num; string name;};class Student1:public Student{ public: St...
2018-05-19 15:54:01
608
原创 C语言之公用继承2
#include <iostream>using namespace std;class Student{ protected: int num; string name;};class Student1:public Student{ public: void get2() { cin>>num>>name>>sex>>sc...
2018-05-19 15:48:23
107
原创 C语言之公用继承1
#include <iostream>using namespace std;class Student{ public: void get1() { cin>>num>>name; } void display1() { cout<<"num:"<<num<<endl; cout<&a
2018-05-19 15:45:39
132
原创 数据结构之层序遍历二叉树
#include <iostream>using namespace std;struct BitNode { char data; BitNode *lchild; BitNode *rchild;};struct LinkNode { BitNode *data; LinkNode *next;};struct LinkQueue{ LinkNode *front; LinkNod...
2018-05-17 19:40:43
418
原创 数据结构之复制二叉树
#include <iostream>using namespace std;struct BitNode{ char data; BitNode *lchild; BitNode *rchild;};void create(BitNode *&T){ char ch; cin>>ch; if(ch=='#') T=NULL; else { T=new BitN...
2018-05-16 21:16:08
1836
原创 C++之静态数据成员
#include <iostream>using namespace std;struct Box{ public: Box(int,int); Box(int,int,int); int volume(); void show() { cout<<"height="<<height<<endl; } private: ...
2018-05-16 12:00:11
182
Python实现字典.zip
2019-06-30
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人