摘要: 当用二叉链表作为二叉树的存储结构时,因为每个结点中只有指向其左、右儿子结点的指针,所以从任一结点出发只能直接找到该结点的左、右儿子。在一般情况下靠它无法直接找到该结点在某种 遍历序下的前驱和后继结点。如果在每个结点中增加指向其前驱和后继结点的指针,将降低存储空间的效率。 我们可以证明:在n个结点的二 阅读全文
posted @ 2016-04-20 21:17 *尘封的记忆* 阅读(527) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 #include 3 #include 4 using namespace std; 5 template 6 struct Node 7 { 8 K _key; 9 V _value; 10 Node*_next; 11 Node(const K& key, const V& valu... 阅读全文
posted @ 2016-04-19 18:13 *尘封的记忆* 阅读(209) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 using namespace std; 3 template 4 struct BSTNode 5 { 6 K _key; 7 V _value; 8 BSTNode *_left; 9 BSTNode *_right; 10 BSTNode(const K&key,const V&val... 阅读全文
posted @ 2016-04-18 17:25 *尘封的记忆* 阅读(214) 评论(0) 推荐(0) 编辑
摘要: 广义表的实现: 阅读全文
posted @ 2016-04-17 20:59 *尘封的记忆* 阅读(185) 评论(0) 推荐(0) 编辑
摘要: 题目:数组中有一个数字出现的次数超过了数组长度的一半,找出这个数字。 分析: 1.首先我们想到如果是一个排序好的数组,那么我们只需要遍历一次数组,统计好每个数字出现的次数,如果大于数组长度的一半就输出这个字。或者只需要直接输出array[N/2]的值即可。 2.如果是杂乱无章的数据我们可能回想先排序 阅读全文
posted @ 2016-04-14 16:03 *尘封的记忆* 阅读(363) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 #include 3 #include 4 using namespace std; 5 6 //Huffman树的节点类 7 typedef struct Node 8 { 9 char value; //结点的字符值 10 int weight; //结点字符出现... 阅读全文
posted @ 2016-04-13 21:35 *尘封的记忆* 阅读(313) 评论(0) 推荐(0) 编辑
摘要: 面试题:二叉搜索树的后序遍历序列题目:输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历结果。如果是刚返回true,否则返回false。假设输入的数组的任意两个数字都互不相同。 正确答案: 例如输入数组{5,7,6,9,11,10,8},则返回true,因为这个整数序列是下图二叉搜索树的后序遍 阅读全文
posted @ 2016-04-11 11:15 *尘封的记忆* 阅读(2697) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 #include 3 #include 4 using namespace std; 5 template 6 struct BinaryTreeNode 7 { 8 T _data; 9 BinaryTreeNode* _left; 10 BinaryTreeNode* _right; 11 Binary... 阅读全文
posted @ 2016-04-10 11:52 *尘封的记忆* 阅读(290) 评论(0) 推荐(0) 编辑
摘要: 计数排序是一种算法复杂度 O(n) 的排序方法,适合于小范围集合的排序。计数排序是一个类似于桶排序的排序算法,其优势是对已知数量范围的数组进行排序。它创建一个长度为这个数据范围的数组countArray,countArray中每个元素记录要排序数组中对应记录的出现个数。这个算法于1954年由 Har 阅读全文
posted @ 2016-04-10 11:08 *尘封的记忆* 阅读(204) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 3 using namespace std; 4 5 typedef int QueueElement; 6 7 struct Node 8 9 { 10 11 Node *next; 12 13 QueueElement data; 14 15 Node(QueueElement value, Nod... 阅读全文
posted @ 2016-04-06 21:32 *尘封的记忆* 阅读(138) 评论(0) 推荐(0) 编辑