coderLucas

Miracles happen every day.

随笔分类 -  DataStruct

摘要:概述 哈夫曼树:树的带权路径长度达到最小。 构造规则 1. 将w1、w2、…,wn看成是有n 棵树的森林(每棵树仅有一个结点); 2. 在森林中选出根结点的权值最小的两棵树进行合并,作为一棵新树的左、右子树,且新树的根结点权值为其左、右子树根结点权值之和; 3. 从森林中删除选取的两棵树,并将新树加入森林; 4. 重复(02)、(03)步,直到森林中只剩一... 阅读全文
posted @ 2014-05-19 14:30 lucas hsueh 阅读(292) 评论(0) 推荐(0)
摘要:红黑树概念 特殊的二叉查找树,每个节点上都有存储位表示节点的颜色是红(Red)或黑(Black)。时间复杂度是O(lgn),效率高。 特性: (1)每个节点或者是黑色,或者是红色。 (2)根节点是黑色。 (3)每个叶子节点(NIL)是黑色。(只为空(NIL或null)的节点) (4)如果一个节点是红色的,则它的子节点必须是黑色的。(黑结点可连续,红结点不能连续) (5)从一个节点到该... 阅读全文
posted @ 2014-05-17 14:40 lucas hsueh 阅读(769) 评论(1) 推荐(0)
摘要:伸展树概念 伸展树(Splay Tree)是一种二叉排序树,它能在O(log n)内完成插入、查找和删除操作。它由Daniel Sleator和Robert Tarjan创造。 (01) 伸展树属于二叉查找树,即它具有和二叉查找树一样的性质:假设x为树中的任意一个结点,x节点包含关键字key,节点x的key值记为key[x]。如果y是x的左子树中的一个结点,则key[y] = key[x... 阅读全文
posted @ 2014-05-17 10:38 lucas hsueh 阅读(374) 评论(0) 推荐(0)
摘要:基本概念 AVL树:树中任何节点的两个子树的高度最大差别为1。 AVL树的查找、插入和删除在平均和最坏情况下都是O(logn)。 AVL实现 AVL树的节点包括的几个组成对象: (01) key -- 是关键字,是用来对AVL树的节点进行排序的。 (02) left -- 是左孩子。 (03) right -- 是右孩子。 (04) heig... 阅读全文
posted @ 2014-05-16 15:54 lucas hsueh 阅读(246) 评论(0) 推荐(0)
摘要:二叉查找树,二叉搜索树,Binary Search Tree 二叉查找树性质:左孩子 using namespace std; template class BSTNode { public: T key; BSTNode *leftchild; BSTNode *rigthchild; ... 阅读全文
posted @ 2014-05-15 17:39 lucas hsueh 阅读(213) 评论(0) 推荐(0)
摘要:一、基本概念 度:结点拥有的子树数目。 树的度:各结点度的最大值。 树的深度(高度):树中结点的最大层次(根为第一层) 二、树的存储结构 顺序存储:双亲表示法 链式存储:1.孩子表示法 2.孩子兄弟表示法(第一个孩子、右兄弟) 三、二叉树 1.二叉树的性质 (1)第i层最多2^(i-1)个结点 (2)深度为k的二叉树最... 阅读全文
posted @ 2014-05-06 15:24 lucas hsueh 阅读(339) 评论(0) 推荐(0)
摘要:1: //sqqueue.cpp 2: 3: #include "sqqueue.h" 4: 5: SqQueue::SqQueue() 6: { 7: front = 0; 8: rear = 0; 9: } 10: 11: SqQueue::~SqQueue() 12: { 13: 14: } 15: 16: void SqQueue::ClearQue... 阅读全文
posted @ 2014-05-06 13:33 lucas hsueh 阅读(256) 评论(0) 推荐(0)
摘要:1: //queue.cpp 2: 3: #include "queue.h" 4: 5: Queue::Queue() 6: { 7: front = new Node; 8: rear = new Node; 9: front->next = NULL; 10: rear = front; 11: length = 0; 12: } 13: 14:... 阅读全文
posted @ 2014-05-06 13:32 lucas hsueh 阅读(174) 评论(0) 推荐(0)
摘要:1: //linkstack.cpp 2: 3: #ifndef LINKSTACK_CPP_CPP 4: #define LINKSTACK_CPP_CPP 5: 6: #include 7: #include "linkstack.h" 8: 9: template 10: LinkStack::LinkStack() 11: { 12: head = new ... 阅读全文
posted @ 2014-05-06 13:31 lucas hsueh 阅读(186) 评论(0) 推荐(0)
摘要:1: //sqstack.cpp 2: #ifndef SQSTACK_CPP_CPP 3: #define SQSTACK_CPP_CPP 4: 5: #include "sqstack.h" 6: #include 7: 8: template 9: SqStack::SqStack(): 10: top(-1),maxsize(MAXSIZE) 11: { 12: ... 阅读全文
posted @ 2014-05-06 13:30 lucas hsueh 阅读(252) 评论(0) 推荐(0)
摘要:需要注意的问题:类模板无法分开链接问题。 类模板在编译的时候没有错误,但是在链接过程中会报错 error LNK2019: unresolved external symbol "public: __thiscall LinkList::~LinkList(void)" (??1?$LinkList@H@@QAE@XZ) referenced in function _main 这是由于类模... 阅读全文
posted @ 2014-05-06 13:29 lucas hsueh 阅读(401) 评论(0) 推荐(0)
摘要:1: //sqlist.cpp 2: #include "sqlist.h" 3: #include 4: 5: void SqList::InitList() 6: { 7: length = 0; 8: } 9: 10: bool SqList::ListEmpty() 11: { 12: return (0 == length); 13: } 14: 1... 阅读全文
posted @ 2014-05-06 13:26 lucas hsueh 阅读(248) 评论(0) 推荐(0)
摘要:一、简单模式匹配算法(略,逐字符比较即可)二、KMP模式匹配算法next数组:j为字符序号,从1开始。(1)当j=1时,next=0;(2)当存在前缀=后缀情况,next=相同字符数+1;(3)当前缀 != 后缀且j != 1时,next=1。如下: abcdexnext=011111 abcabx... 阅读全文
posted @ 2014-05-06 11:26 lucas hsueh 阅读(271) 评论(0) 推荐(0)