随笔分类 -  数据结构

摘要:#include<iostream>#include<stack>#include<string>using namespace std;#define maxEdge 0x3f3f3ffconst int MAX_V_NUM=100; //点的最大值int Edges[MAX_V_NUM][MAX_V_NUM];//图的邻接矩阵int indegree[MAX_V_NUM]; //存储各顶点的入度string Vert[MAX_V_NUM]; //顶点信息int TE[MAX_V_NUM]; //顶点的最早开始时间int TL[MAX_V_NUM]; // 阅读全文
posted @ 2012-12-07 16:01 ♂咱說 ろ算 阅读(304) 评论(0) 推荐(0)
摘要://全排列#include<iostream>#include<vector>#include<stack>#include<queue>#include<list>#include<set>#include<map>#include<cmath>#include<string>#include<algorithm>using namespace std;void main(){ vector<int>a; int i; for(i=1;i<=3;i++) 阅读全文
posted @ 2012-12-07 15:59 ♂咱說 ろ算 阅读(257) 评论(0) 推荐(0)
摘要://最大最小堆struct node{ int i,n; node (){} node (int x,int y){ i=x;n=y; } bool operator<(const node& b) const { return n>b.n; }};int main(){ priority_queue<node> Q; Q.push(node(1,2)); Q.push(node(2,3)); Q.push(node(1,3)); Q.push(node(3,4)); while(!Q.empty()) { printf("%d %d\n", 阅读全文
posted @ 2012-11-24 12:14 ♂咱說 ろ算 阅读(364) 评论(0) 推荐(0)
摘要:#include<iostream>using namespace std;char B[20];//默认为'\0'void getpowerset(int i,char a[]){ if(i>=strlen(a)) { cout<<"{"; if(B[0]) { for(int j=0;j<strlen(B)-1;j++) cout<<B[j]<<","; cout<<B[j]<<"},"; } else cout<<&q 阅读全文
posted @ 2012-11-23 22:16 ♂咱說 ろ算 阅读(371) 评论(0) 推荐(0)
摘要:#include<iostream>#include<list>using namespace std;void main(){ list<int>a; for(int i=0;i<10;i++) a.push_back(i); list<int>::iterator p; for(p=a.begin();p!=a.end();p++) { cout<<*p<<" "; } cout<<endl; for(p=a.begin();p!=a.end();) { if((*p)%2==0) 阅读全文
posted @ 2012-11-23 22:14 ♂咱說 ろ算 阅读(408) 评论(0) 推荐(0)
摘要:#include <iostream>using namespace std;#define MAX_TREE_SIZE 100typedef struct //节点结构{ char data; int parent; //双亲位置域}PTNode;typedef struct //树结构{ PTNode node[MAX_TREE_SIZE]; int count; //根的位置和节点个数}PTree;//初始化树void init_ptree(PTree &tree){ tree.count=-1;}//添加节点void add_ptnode(PTree &tr 阅读全文
posted @ 2012-11-23 22:01 ♂咱說 ろ算 阅读(651) 评论(0) 推荐(0)
摘要:#include<iostream>#include<stack>using namespace std;const int MaxSize=100;int gcd(int a,int b){ int c; while(a%b!=0) { c=a%b; a=b; b=c; } return b;}int main(){ stack<int>S,Q; int num,i; cout<<"请输入有多少个数:"; cin>>num; int number[MaxSize]; for(i=0;i<num;i++) { 阅读全文
posted @ 2012-11-23 21:58 ♂咱說 ろ算 阅读(215) 评论(0) 推荐(0)
摘要://queen.hclass Queen{private: int number;//皇后数 bool *row;//行是否有随机数 bool *diag;//主对角线是否有皇后数 bool *backDiag;//反对角线是否有皇后数 int *x;//解 static int num;//解得个数 //辅助函数 void BackTracking(int c);//回溯法递归求解 void Show();//显示解public: Queen(); virtual ~Queen(); void Run();};int Queen::num=0;Queen::Queen(){ cout< 阅读全文
posted @ 2012-11-22 23:12 ♂咱說 ろ算 阅读(225) 评论(0) 推荐(0)
摘要:#include<iostream>#include<windows.h>using namespace std;typedef char TElemType ;typedef enum PointerTag{Link,Thread};typedef struct BiThrNode{ TElemType data; struct BiThrNode *lchild,*rchild; PointerTag LTag,RTag;}BiThrNode,*BiThrTree;void CreatTree(BiThrTree &T){ TElemType item; c 阅读全文
posted @ 2012-11-22 23:01 ♂咱說 ろ算 阅读(272) 评论(0) 推荐(0)
摘要://main.cpp#include<iostream>using namespace std;typedef char TElemType;typedef struct node{ TElemType data; struct node *lchild; struct node *rchild;}BiTNode,*BinTree;BiTNode *creatBinTree(TElemType *VLR,TElemType *LVR,int n)//由中序序列和前序序列构造二叉树{ if(n==0) return NULL; int k=0; while(VLR[0]!=LVR[k 阅读全文
posted @ 2012-11-22 23:00 ♂咱說 ろ算 阅读(402) 评论(0) 推荐(0)
摘要:#include<iostream>#include<string>using namespace std;#define maxnum 100#define maxlength 10000typedef int ElemType;typedef int WType;typedef struct{ ElemType tu[maxnum][maxnum]; //邻接矩阵 string point[maxnum]; //顶点矩阵 int point_num; //顶点个数}Graph;void input(Graph &G){ cout<<"请 阅读全文
posted @ 2012-11-22 22:58 ♂咱說 ろ算 阅读(304) 评论(0) 推荐(0)
摘要:#include<iostream>#include<string>using namespace std;#define maxnum 100#define maxlength 10000typedef int ElemType;typedef int WType;typedef struct{ ElemType tu[maxnum][maxnum]; //邻接矩阵 string point[maxnum]; //顶点矩阵 int point_num; //顶点个数}Graph;void input(Graph &G){ cout<<"请 阅读全文
posted @ 2012-11-22 22:57 ♂咱說 ろ算 阅读(294) 评论(0) 推荐(0)
摘要://graph.h#include<iostream>#include<cstdlib>#include<queue>using namespace std;#define maxVert 20#define maxWeight 10000typedef char VType;typedef double WType;typedef struct{ int numVetr,numEdges;//点和边的个数 VType *VertList;//点矩阵 WType **Edge;//邻接矩阵}Graph;void InitGraph(Graph &G) 阅读全文
posted @ 2012-11-22 22:56 ♂咱說 ろ算 阅读(264) 评论(0) 推荐(0)
摘要://迷宫#include<iostream>#include<ctime>#include<windows.h>#include<fstream>using namespace std;struct offsets{ int a,b; char *dir;};struct node{ int x,y;};struct tag{ int x,y; char *dir;};class MiGong{private: int map[30][30];//地图矩阵 int mark[30][30];//标志矩阵 offsets move[4];//各个方 阅读全文
posted @ 2012-11-22 22:55 ♂咱說 ろ算 阅读(219) 评论(0) 推荐(0)
摘要:#include<iostream>#include<stack>using namespace std;const int MaxSize=100;int gcd(int a,int b){ int c; while(a%b!=0) { c=a%b; a=b; b=c; } return b;}int main(){ stack<int>S,Q; int num,i; cout<<"请输入有多少个数:"; cin>>num; int number[MaxSize]; for(i=0;i<num;i++) { 阅读全文
posted @ 2012-11-22 22:50 ♂咱說 ろ算 阅读(268) 评论(0) 推荐(0)
摘要:#include<iostream>#include<string>using namespace std;#define LIST_INIT_SIZE 100#define LISTINCREMENT 10typedef int Status,ElemType;typedef struct{ ElemType *elem; int length; int listsize;}SqList;void Init_Sq(SqList &L){ L.elem=new ElemType[LIST_INIT_SIZE]; if(L.elem==NULL) exit(1); 阅读全文
posted @ 2012-09-26 23:14 ♂咱說 ろ算 阅读(247) 评论(0) 推荐(0)
摘要:#include<iostream>using namespace std;typedef int ElemType;typedef struct List{ ElemType data; struct List *next;}LinkNode,*LinkList;LinkNode *creat_List(int number){ LinkList first=new LinkNode; first->data=-1; LinkList p=first; if(first==NULL) { cout<<"分配内存失败"<<endl; 阅读全文
posted @ 2012-09-26 23:13 ♂咱說 ろ算 阅读(295) 评论(0) 推荐(0)
摘要:#include<iostream>using namespace std;typedef int ElemType ;typedef struct node{ElemType data;struct node *next;}LinkNode,*LinkList;void creat(LinkList&first,LinkNode*&last,int endTage)//递归尾插法建立链表{ElemType data;cout<<"请建立数据"<<endl;cin>>data;if(endTage==data) 阅读全文
posted @ 2012-09-26 23:10 ♂咱說 ろ算 阅读(277) 评论(0) 推荐(0)