摘要: /* * description: 图的欧拉路径搜索 * writeby: Nick * date: 2012-10-25 23:32 * */#include <iostream>#include <vector>#include <stack>using namespace std;struct Edge{ int v, w; Edge(int v=-1, int w=-1) : v(v), w(w) {}};class Graph{ private: int vcount, ecount; ... 阅读全文
posted @ 2012-10-26 15:42 wouldguan 阅读(808) 评论(0) 推荐(0) 编辑
摘要: 一个有V个顶点的图G是一棵树,条件是当且仅当她满足一下4个条件中的任意一个:1. G有V-1条边,且无环。2. G的V-1条边,且是连通的。3. G中仅有一条简单路径使每一对顶点相连接。4. G是连通的,从中去除任意一条边都不会使其不连通。 阅读全文
posted @ 2012-10-26 10:14 wouldguan 阅读(245) 评论(0) 推荐(0) 编辑
摘要: /* * description: 图的哈密顿路径搜索 * writeby: Nick * date: 2012-10-25 23:32 * */#include <iostream>#include <vector>using namespace std;struct Edge{ int v, w; Edge(int v=-1, int w=-1) : v(v), w(w) {}};class Graph{ private: int vcount, ecount; //记录顶点总数,边总数... 阅读全文
posted @ 2012-10-26 10:14 wouldguan 阅读(2869) 评论(0) 推荐(0) 编辑
摘要: /* * description: 图的一条简单路径搜索,不是最短的 * writeby: Nick * date: 2012-10-25 23:32 * */#include <iostream>#include <vector>using namespace std;struct Edge{ int v, w; Edge(int v=-1, int w=-1) : v(v), w(w) {}};class Graph{ private: int vcount, ecount; //记录顶... 阅读全文
posted @ 2012-10-26 10:13 wouldguan 阅读(1335) 评论(0) 推荐(0) 编辑
摘要: /* * description: 图的ADT实现(邻接矩阵) * writeby: Nick * date: 2012-10-25 23:32 * */#include <iostream>#include <vector>using namespace std;struct Edge{ int v, w; Edge(int v=-1, int w=-1) : v(v), w(w) {}};class Graph{ private: int vcount, ecount; //记录顶点总数... 阅读全文
posted @ 2012-10-25 23:35 wouldguan 阅读(1693) 评论(0) 推荐(0) 编辑
摘要: /* * description: 链表归并排序示例 * writeby: nick * date: 2012-10-23 16:35 * */#include <iostream>#define maxN 10using namespace std;struct node{ int item; node *next; node(int n){item=n; next=0;}};typedef node *link;link merge(link a, link b) //合并a b 链表{ node du... 阅读全文
posted @ 2012-10-25 10:29 wouldguan 阅读(3021) 评论(0) 推荐(0) 编辑
摘要: /* * description: 归并排序示例 * writeby: nick * date: 2012-10-23 16:35 * */#include <iostream>#define maxN 10using namespace std;template <class Item>void merge(Item a[], int l, int m, int r){ int i,j; Item tmp[maxN]; for(i=l; i<=m; i++) tmp[i] = a[i]; // / fo... 阅读全文
posted @ 2012-10-24 16:37 wouldguan 阅读(270) 评论(0) 推荐(0) 编辑
摘要: /* * description: 快速排序示例 * writeby: nick * date: 2012-10-23 16:16 * */#include <iostream>#include <stack>using namespace std;//递归版本void quicksort(int a[], int l, int r){ int mid = a[(l+r) / 2]; int lwalker = l, rwalker = r; while(lwalker < rwalker) { w... 阅读全文
posted @ 2012-10-24 14:24 wouldguan 阅读(3683) 评论(0) 推荐(0) 编辑
摘要: /* * description: 快速排序示例 * writeby: nick * date: 2012-10-23 16:16 * */#include <iostream>using namespace std;void quicksort(int a[], int l, int r){ int mid = a[(l+r) / 2]; int lwalker = l, rwalker = r; while(lwalker < rwalker) { while(a[lwalker] < mid)... 阅读全文
posted @ 2012-10-24 13:14 wouldguan 阅读(329) 评论(0) 推荐(0) 编辑
摘要: /* * description: 计算二叉树的层数和节点数 * writeby: nick * date: 2012-10-23 16:16 * */#include <iostream>using namespace std;struct node{ int item; node *l, *r; node(int n) {item=n; l=0; r=0;}};typedef node *link;//计算节点总数int count(link h){ if(h==0) return 0; retu... 阅读全文
posted @ 2012-10-23 16:19 wouldguan 阅读(6220) 评论(0) 推荐(0) 编辑