目 录
1、顺序表 ................................................................................................. 1
Seqlist.h .............................................................................................. 1
Test.cpp ............................................................................................... 7
2、单链表 ................................................................................................. 8
ListNode.h ............................................................................................. 9
SingleList.h .......................................................................................... 11
test.cpp .............................................................................................. 22
3、双向链表 .............................................................................................. 25
NodeList.h ............................................................................................ 25
DoubleList.h .......................................................................................... 27
Test.cpp .............................................................................................. 38
4、循环链表 .............................................................................................. 40
ListNode.h ............................................................................................ 40
CircularList.h ........................................................................................ 42
Test.cpp .............................................................................................. 53
5、顺序栈 ................................................................................................ 56
SeqStack.h ............................................................................................ 56
Test.cpp .............................................................................................. 61
6、链式栈 ................................................................................................ 62
StackNode.h ........................................................................................... 63
LinkStack.h ........................................................................................... 64
Test.cpp .............................................................................................. 68
7、顺序队列 .............................................................................................. 70
SeqQueue.h ............................................................................................ 71
Test.cpp .............................................................................................. 76
8、链式队列 .............................................................................................. 78
QueueNode.h ........................................................................................... 79
LinkQueue.h ........................................................................................... 80
Test.cpp .............................................................................................. 84
9、优先级队列 ............................................................................................ 86
QueueNode.h ........................................................................................... 87
Compare.h ............................................................................................. 88
PriorityQueue.h ....................................................................................... 90
Test.cpp .............................................................................................. 96
10、串 ................................................................................................... 99
MyString.h ............................................................................................ 99
MyString.cpp ......................................................................................... 102
test.cpp ............................................................................................. 114
11、二叉树 .............................................................................................. 117
BinTreeNode.h ........................................................................................ 117
BinaryTree.h ......................................................................................... 126
Test.cpp ............................................................................................. 140
12、线索二叉树 .......................................................................................... 142
ThreadNode.h ......................................................................................... 143
ThreadTree.h ......................................................................................... 144
ThreadInorderIterator.h .............................................................................. 145
test.cpp ............................................................................................. 157
13、堆 .................................................................................................. 158
MinHeap.h ............................................................................................ 159
test.cpp ............................................................................................. 167
14、哈夫曼树 ............................................................................................ 168
BinTreeNode.h ........................................................................................ 168
BinaryTree.h ......................................................................................... 171
MinHeap.h ............................................................................................ 177
Huffman.h ............................................................................................ 182
Test.cpp ............................................................................................. 184
15、树 .................................................................................................. 185
QueueNode.h .......................................................................................... 186
LinkQueue.h .......................................................................................... 187
TreeNode.h ........................................................................................... 191
Tree.h ............................................................................................... 192
test.cpp ............................................................................................. 211
16、B+树 ................................................................................................ 214
BTreeNode.h .......................................................................................... 214
BTree.h .............................................................................................. 218
test.cpp ............................................................................................. 243
17、图 .................................................................................................. 245
MinHeap.h ............................................................................................ 246
Edge.h ............................................................................................... 251
Vertex.h ............................................................................................. 252
Graph.h .............................................................................................. 254
test.cpp ............................................................................................. 279
18、排序 ................................................................................................ 282
Data.h ............................................................................................... 282
QueueNode.h .......................................................................................... 289
LinkQueue.h .......................................................................................... 293
Sort.h ............................................................................................... 298
test.cpp ............................................................................................. 314
2008-9-3
数据结构算法实现
1、顺序表
Seqlist.h
const int DefaultSize=100;
template class SeqList{
public:
SeqList(int sz=DefaultSize)
:m_nmaxsize(sz),m_ncurrentsize(-1){
if(sz>0){
m_elements=new Type[m_nmaxsize];
}
}
~SeqList(){
1
2008-9-3
数据结构算法实现
delete[] m_elements;
}
int Length() const{
return m_ncurrentsize+1;
}
int Find(Type x) const;
int IsElement(Type x) const;
int Insert(Type x,int i);
int Remove(Type x);
int IsEmpty(){
return m_ncurrentsize==-1;
}
int IsFull(){
//get the length
//find the position of x
//is it in the list
//insert data
//delete data
return m_ncurrentsize==m_nmaxsize-1;
}
2
数据结构算法实现
Type Get(int i){
//get the ith data
2008-9-3
return i<0||i>m_ncurrentsize?(cout<<"can't find the element"< int SeqList::Find(Type x) const{
for(int i=0;i