随笔分类 - 数据结构
一些数据结构的知识。
摘要:如果表够大,散列函数足够好,那么散列表在查找上具有O(1)的时间复杂度。但是我们考虑出现冲突的情况,如果使用分离链表法来处理冲突。那么链表的平均长度等于装填因子a(元素个数与散列表大小的比值)的大小。所以不成功查找的复杂度为a,成功查找的复杂度为1 + a/2。代码实现如下: 1 #include...
阅读全文
摘要:重新实现了单链表,以指针而非哑节点的方式去指向第一个节点。代码如下: 1 /* 2 * 第二版链表实现 3 * 原先的实现,是以哑节点的方式来做链表的头部。 4 * 现在我们使用一个指针来做链表的头部,节约一个struct Node的空间 5 */ 6 7 #includ...
阅读全文
摘要:代码实现如下: 1 #include 2 #include 3 #include 4 5 #define MIN (1 left); 23 MakeEmpty(t->right); 24 free(t); 25 } 26 return...
阅读全文
摘要:代码如下: 1 #include 2 #include 3 4 typedef int itemType; 5 typedef struct QueueRecord* queue; 6 7 /* 对于size大小的数组,如果没有额外的变量记录大小,而仅仅通过front和rear...
阅读全文
摘要:队列的链表实现比数组实现要难一些。队列的链表实现比栈的链表实现也要难一些。代码如下: 1 #include 2 #include 3 4 typedef int itemType; 5 struct Node; 6 struct Queue; 7 typedef struct N...
阅读全文
摘要:代码如下: 1 #include 2 #include 3 4 #define EMPTY_STACK (-1) 5 #define MIN_STACK_SIZE (3) 6 7 typedef int itemType; 8 struct Node; 9 typedef ...
阅读全文
摘要:代码如下: 1 #include 2 #include 3 4 typedef int itemType; 5 struct Node; 6 typedef struct Node *pNode; 7 typedef pNode stack; 8 9 struct Node...
阅读全文
摘要:代码实现如下: 1 #include 2 #include 3 4 typedef int itemType; 5 struct Node; 6 typedef struct Node *pNode; 7 typedef pNode list; 8 typedef pNode ...
阅读全文
摘要:直接看实现吧: 1 #include 2 #include 3 4 typedef int itemType; 5 struct Node; 6 typedef struct Node *pNode; 7 typedef pNode list; 8 typedef pNode ...
阅读全文
摘要:直接看实现吧: 1 #include 2 #include 3 4 typedef int itemType; 5 struct Node; 6 typedef struct Node *pNode; 7 typedef pNode list; 8 typedef pNode ...
阅读全文
摘要:与上篇《二叉堆 - 最小堆》类似,只不过堆序(heap order)从内部节点小于左右子节点变成了内部节点大于左右子节点。代码如下: 1 #include 2 #include 3 4 #define MIN (1items =(Item*)malloc((maxItems+1)*si...
阅读全文
摘要:二叉堆:一般我们拿来用的就是最大堆和最小堆。最小堆:每个节点的值比它的左右子节点的值要大。代码实现如下:参考Mark Allen Weiss《数据结构和算法分析》(第二版) 1 #include 2 #include 3 4 #define MIN (1items =(Item*)ma...
阅读全文
摘要:读了Robert Sedgewick的《算法:C语言实现》(第三版)的第五章,了解了许多关于树,特别是二叉树的知识。这里总结一下。直接看代码(C++)吧。 1 #include 2 #include 3 #include 4 #include 5 6 #define null ...
阅读全文