![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构
文章平均质量分 64
Silent-Jy
生活是坚持出来的。
展开
-
并查集模板
#include typedef struct { int rank; //节点对应的秩 int parent; //双亲节点,即所属的集合 }UFSTree; /** 初始化集合,使每个节点双亲都指向自己 n为节点的个数 */ void MakeSet(UFSTree t[],int n) { for(int i=0;i<n;i++) { t[i].parent = i; t原创 2012-12-31 12:48:50 · 540 阅读 · 0 评论 -
BFS和DFS模板
#include #define N 100 /**DFS深度优先搜索是从图中的某个顶点出发,先访问初始点,然后访问其邻接点u(没有被访问过,下同), 再访问u的邻接点,一直到深入访问*/ //邻接表结构 typedef struct Anode { int adj; //终点位置 struct Anode *next;//下一条边 }ArcNode; typedef struct { A原创 2012-12-31 12:47:53 · 3313 阅读 · 0 评论 -
快速排序模板和二分查找
#include /**在执行的过程中分为两段时有可能不均,使得时间复杂度为O(n^2), 可以采用随机化版本来解决这个问题*/ void QuickSort(int a[],int low,int high) { int i = low,j = high,tmp; if (low<high) { tmp = a[i]; while(i!=j) { while(j>i原创 2012-12-31 12:51:44 · 759 阅读 · 0 评论 -
堆排序模板
#include /*大根堆,即最大值在树的根节点,数组0下标不算*/ void shift(int a[],int low,int high)//调整堆 { int i = low,j = 2*i; int tmp = a[i]; while(j<=high) { if (j<high && a[j]<a[j+1]) //如果左节点比右节点小,则指向右节点 j++; if原创 2012-12-31 15:26:09 · 936 阅读 · 0 评论 -
希尔排序
/*和插入排序类似,在插入排序的基础进行分组*/ void ShellSort(int a[],int n) { int i,j,gap; int tmp; gap = n/2; //初始化增量 while(gap>0) // { for(i=gap;i<n;i++) //对所有相隔gap位置的所有元素进行插入排序 { tmp = a[i]; j = i-gap;原创 2013-01-01 22:21:04 · 370 阅读 · 0 评论 -
BCL-1338:真题之清华面试篇
http://www.bianchengla.com/course/ds2009/practise/problem?id=1338 /* //第一种解法。按题目要求做的 #include #include typedef struct Node { int data; struct Node *next; }LNode; LNode *h; void CreatList(int n)原创 2013-01-25 17:21:44 · 1019 阅读 · 0 评论 -
BCL-1339:链表基础练习题(1)
/* //第一种方法。按照题目要求 #include #include typedef struct Node { int data; struct Node *next; }LNode; LNode *h; void CreatList(int n) { h = (LNode*)malloc(sizeof(LNode)); h->next = NU原创 2013-01-25 18:51:37 · 509 阅读 · 0 评论 -
HDU-1022:Train Problem I
/* 火车进站出站问题。 需要注意的是初始序列是输入时给的。而不是默认的123.... */ #include #include using namespace std; #define N 10 char in[N],out[N]; bool inp[N*2]; //用来记录进出顺序,true为in,false为out int main() { stackst; int n,k;原创 2013-01-26 18:10:46 · 587 阅读 · 0 评论