没有合适的资源?快使用搜索试试~ 我知道了~
首页用C++实现数据结构中的各种算法
用C++实现数据结构中的各种算法
4星 · 超过85%的资源 需积分: 50 35 下载量 88 浏览量
更新于2023-03-16
评论 10
收藏 676KB DOC 举报
使用模板实现数据结构中各种算法。如链表,队列,二叉树,红黑树,堆,图,优先级队列,哈夫曼树数据结构的实现等
资源详情
资源评论
资源推荐
目 录
目 录..........................................................................................................................................................................................................................................................................................1
1、顺序表.................................................................................................................................................................................................................................................................................1
Seqlist.h.............................................................................................................................................................................................................................................................................1
Test.cpp..............................................................................................................................................................................................................................................................................4
2、 单链表................................................................................................................................................................................................................................................................................5
ListNode.h.........................................................................................................................................................................................................................................................................5
SingleList.h........................................................................................................................................................................................................................................................................6
test.cpp.............................................................................................................................................................................................................................................................................12
3、 双向循环链表..................................................................................................................................................................................................................................................................13
NodeList.h.......................................................................................................................................................................................................................................................................13
DoubleList.h....................................................................................................................................................................................................................................................................14
Test.cpp............................................................................................................................................................................................................................................................................20
4、 单项循环链表..................................................................................................................................................................................................................................................................21
ListNode.h.......................................................................................................................................................................................................................................................................22
CircularList.h...................................................................................................................................................................................................................................................................22
Test.cpp............................................................................................................................................................................................................................................................................28
5、 顺序栈..............................................................................................................................................................................................................................................................................29
SeqStack.h.......................................................................................................................................................................................................................................................................30
Test.cpp............................................................................................................................................................................................................................................................................32
6、 链式栈..............................................................................................................................................................................................................................................................................33
StackNode.h.....................................................................................................................................................................................................................................................................33
LinkStack.h......................................................................................................................................................................................................................................................................34
Test.cpp............................................................................................................................................................................................................................................................................36
7.顺序队列..............................................................................................................................................................................................................................................................................37
SeqQueue.h......................................................................................................................................................................................................................................................................38
Test.cpp............................................................................................................................................................................................................................................................................40
8、链式队列...........................................................................................................................................................................................................................................................................42
QueueNode.h...................................................................................................................................................................................................................................................................42
LinkQueue.h....................................................................................................................................................................................................................................................................42
Test.cpp............................................................................................................................................................................................................................................................................45
9、优先级队列.......................................................................................................................................................................................................................................................................46
QueueNode.h...................................................................................................................................................................................................................................................................46
Compare.h.......................................................................................................................................................................................................................................................................47
PriorityQueue.h...............................................................................................................................................................................................................................................................48
Test.cpp............................................................................................................................................................................................................................................................................51
10、串.....................................................................................................................................................................................................................................................................................53
MyString.h.......................................................................................................................................................................................................................................................................53
MyString.cpp...................................................................................................................................................................................................................................................................54
test.cpp.............................................................................................................................................................................................................................................................................60
11、二叉树.............................................................................................................................................................................................................................................................................62
BinTreeNode.h................................................................................................................................................................................................................................................................62
BinaryTree.h....................................................................................................................................................................................................................................................................67
Test.cpp............................................................................................................................................................................................................................................................................73
12、线索二叉树.....................................................................................................................................................................................................................................................................75
ThreadNode.h..................................................................................................................................................................................................................................................................75
ThreadTree.h....................................................................................................................................................................................................................................................................76
ThreadInorderIterator.h...................................................................................................................................................................................................................................................76
test.cpp.............................................................................................................................................................................................................................................................................82
13、堆.....................................................................................................................................................................................................................................................................................83
MinHeap.h.......................................................................................................................................................................................................................................................................83
test.cpp.............................................................................................................................................................................................................................................................................87
14、哈夫曼树.........................................................................................................................................................................................................................................................................88
BinTreeNode.h................................................................................................................................................................................................................................................................88
BinaryTree.h....................................................................................................................................................................................................................................................................90
MinHeap.h.......................................................................................................................................................................................................................................................................93
Huffman.h........................................................................................................................................................................................................................................................................96
Test.cpp............................................................................................................................................................................................................................................................................97
15、树.....................................................................................................................................................................................................................................................................................97
QueueNode.h...................................................................................................................................................................................................................................................................97
LinkQueue.h....................................................................................................................................................................................................................................................................98
TreeNode.h....................................................................................................................................................................................................................................................................100
Tree.h.............................................................................................................................................................................................................................................................................101
test.cpp...........................................................................................................................................................................................................................................................................111
16、B+树..............................................................................................................................................................................................................................................................................112
BTreeNode.h..................................................................................................................................................................................................................................................................112
BTree.h..........................................................................................................................................................................................................................................................................114
test.cpp...........................................................................................................................................................................................................................................................................127
17、图...................................................................................................................................................................................................................................................................................128
MinHeap.h.....................................................................................................................................................................................................................................................................128
Edge.h............................................................................................................................................................................................................................................................................131
Vertex.h..........................................................................................................................................................................................................................................................................132
Graph.h..........................................................................................................................................................................................................................................................................132
test.cpp...........................................................................................................................................................................................................................................................................145
18、排序...............................................................................................................................................................................................................................................................................146
Data.h.............................................................................................................................................................................................................................................................................147
QueueNode.h.................................................................................................................................................................................................................................................................150
LinkQueue.h..................................................................................................................................................................................................................................................................153
Sort.h..............................................................................................................................................................................................................................................................................155
test.cpp...........................................................................................................................................................................................................................................................................163
数据结构算法实现 2008-9-3
1、顺序表
Seqlist.h
const int DefaultSize=100;
template <typename Type>
class SeqList{
public:
SeqList(int sz=DefaultSize)
:m_nmaxsize(sz),m_ncurrentsize(-1){
if(sz>0){
m_elements=new Type[m_nmaxsize];
}
}
~SeqList(){
delete[] m_elements;
}
int Length() const{ //get the length
return m_ncurrentsize+1;
}
int Find(Type x) const; //find the position of x
int IsElement(Type x) const; //is it in the list
int Insert(Type x,int i); //insert data
int Remove(Type x); //delete data
1
数据结构算法实现 2008-9-3
int IsEmpty(){
return m_ncurrentsize==-1;
}
int IsFull(){
return m_ncurrentsize==m_nmaxsize-1;
}
Type Get(int i){ //get the ith data
return i<0||i>m_ncurrentsize?(cout<<"can't find the element"<<endl,0):m_elements[i];
}
void Print();
private:
Type *m_elements;
const int m_nmaxsize;
int m_ncurrentsize;
};
template <typename Type> int SeqList<Type>::Find(Type x) const{
for(int i=0;i<m_ncurrentsize;i++)
if(m_elements[i]==x)
return i;
cout<<"can't find the element you want to find"<<endl;
return -1;
}
template <typename Type> int SeqList<Type>::IsElement(Type x) const{
if(Find(x)==-1)
return 0;
return 1;
}
2
剩余63页未读,继续阅读
zcx123456789
- 粉丝: 0
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
- SPC统计方法基础知识.pptx
- MW全能培训汽轮机调节保安系统PPT教学课件.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论2