数据结构各种算法实现(C++模板).docx
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《数据结构各种算法实现(C++模板).docx》由会员分享,可在线阅读,更多相关《数据结构各种算法实现(C++模板).docx(418页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、1、顺序表1Seqlist. h 1Test, cpp 72、单链表9ListNode. h 9SingleList, h 11test, cpp 223、双向链表25NodeList, h 25DoubleList, h 27Test, cpp 384、循环链表40ListNode. h 41CircularList. h 42Test, cpp 535、顺序栈56SeqStack. h 56Test, cpp 616、链式栈63StackNode. h 63LinkStack. h 64Test, cpp 687、顺序队列71SeqQueue. h 71Test, cpp 768、链式队列
2、79QueueNode. h 79LinkQueue. h 80Test, cpp 849、优先级队列87QueueNode. h 87Compare, h 88Pr iorityQueue. h 90Test, cpp 9610、串99MyString. h 99MyString. cpp 102test, cpp 11411、二叉树117BinTreeNode. h 117BinaryTree. h 126Test, cpp 14012、线索二叉树142ThreadNode. h 143ThreadTree. h 144Threadinorderiterator, h 145test, c
3、pp 15713、堆158MinHeap. h 159test, cpp 16714、哈夫曼树168BinTreeNode.h 168BinaryTree. h 171MinHeap. h 177Huffman, h 182Test, cpp 18415、树185QueueNode. h 186LinkQueue. h 187TreeNode. h 191Tree, h 192test, cpp 21116、B+树214BTreeNode. h 214BTree. h 218test, cpp 24317、图245MinHeap. h 246Edge, h 251Vertex, h 252Gr
4、aph, h 254test, cpp 27918、排序282Data, h 282QueueNode. h 289LinkQueue. h 293Sort.h 298test, cpp 3141、顺序表Seqlist.hconst int DefaultSize=100;template class SeqListpublic:SeqList(int sz=DefaultSize):m_nmaxsize(sz),m_ncurrentsize(-1)if(sz0)m_elements=new Typem_nmaxsize;SeqList()delete m_elements;)int Leng
5、th() constreturn m_ncurrentsize+l;)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=-l)int IsFull()return m_ncurrentsize=m_/get the length/find the position of x/is it in the list/insert data/delete datamaxsize-1;)Type
6、Get(int i)/get the ith datareturn im_ncurrentsize?(coutcant find the elementendlf 0) :m_elementsi;)void Print();private:Type *m_elements;const int m_nmaxsize;int m_ncurrentsize;;template int SeqList:Find(Type x) constfor(int i=0;im_ncurrentsize;i+)if(m_elementsi=x)return i;coutcant find the element
7、you want to findendl;return -1;template int SeqList:IsElement(Type x) const if(Find(x)=-l)return 0;return 1;template int SeqList:Insert(Type x, int i)if(im_ncurrentsize+l|m_ncurrentsize=m_nmaxsize-l) coutthe operate is illegali;j) m_elementsj=m_elementsj-1;)m_elementsi=x;return 1;template int SeqLis
8、t int size=m_ncurrentsize;for(int i=0;im_ncurrentsize;)if(m_elementsi=x)for(int j=i;jm_ncurrentsize;j+)m_elementsj=m_elementsj+1;:Remove(Type x)m_ncurrent size;continue;i+;)if(size=m_ncurrentsize)coutcant find the element you want to return 0;)return 1;template void SeqList:Prfor(int i=0;i=m_ncurren
9、tsize;i+)removeendl;int ()couti+l:tm_elementsicoutendlendl;Test.cpp#include #include SeqList.husing namespace std;int main()SeqList test(15);endl;int array 15 = 2,5,8,1,9,9,7,6,4,3,2,9,7,7,9;for(int i=0;i15;i+)test.Insert(arrayi , 0);)test.Insert(1,0);cout(test.Find(0)?cant be found :Be foundtest.Re
10、move(7);test.Print();test.Remove(9);test.Print();test.Remove(0);test.Print();return 0;H) 0 endlendl;2、单链表ListNode.htemplate class SingleList;template class ListNodeprivate:friend typename SingleList;ListNode():m_pnext(NULL)ListNode(const Type item,ListNode *next=NULL):m_data(item),m_pnext(next)ListN
11、ode()m_pnext=NULL;public:Type GetData();friend ostream& operator (streams ,ListNode&);private:Type m_data;ListNode *m_pnext;;template Type ListNode:GetData() return this-m_data;template ostream& operator(ostream& os,ListNode& out)osout.m_data;return os;SingleList.h#include ListNode.htemplate class S
12、ingleListpxiblic:SingleList () :head(new ListNode()SingleList()MakeEmpty();delete head;)public:void MakeEmpty();int Length();ListNode *Find(Type ListNode *Find(int bool Insert(Type item,int Type Remove(int n=0);bool RemoveAl1(Type item)Type Get(int n);void Print();/make the list empty/get the length
13、value,int n); /find thd nth data which is equal to valuei) ;/find the nth datan=0) ;/insert the data in the nth position/remove the nth data/remove all the data which is equal to item/get the nth data/print the listprivate:ListNode *head;;template void SingleListType:ListNode *pdel;while(head-m_pnex
14、t!=NULL)pde1=head-m_pnext;he ad-m_pn ext =pde1-m_pnext;delete pdel;)template int SingleListListNode *pmove=head-m_pnext;int count=0; :MakeEmpty () :Length()while(pmove!=NULL) pmove=pmove-m_pnext; count+;) return count;template ListNode* SingleList:Find(int n) if(n0)coutThe n is out of boundaryendl;
15、return NULL;)ListNode *pmove=head-m_pnext;for(int i=0;im_pnext;)if(pmove=NULL)coutThe n is out of boundaryendl;return NULL;) return pmove; template ListNode* SingleList:Find(Type value,int n) if(nl) coutThe n is illegalendl;return NULL;)ListNode *pmove=head;int count=0;while(count!=n&pmove) pmove=pm
16、ove-m_pnext; if(pmove-m_data=value)count+;)if(pmove=NULL) coutcant find the elementendl; return NULL;)return pmove; template bool SingleList:Insert(Type item, int n)if(n0) coutThe n is illegalendl;return 0;)ListNode *pmove=head;ListNode *pnode=new ListNode(item);if(pnode=NULL)coutApplication error!e
17、ndl;return 0;)for(int i=0;im_pnext;)if(pmove=NULL)coutthe n is illegalm_pnext=pmove-m_pnext;pmove-m_pnext=pnode;return 1;template bool SingleListListNode *pmove=head;ListNode *pdel=head-m_pnext;while(pdel!=NULL)if(pdel-m_data=item)pmove-m_pnext=pdel-m_pnext;delete pdel;pdel=pmove-m_pnext;:Remove All
18、 (Type item) continue;pmove=pmove-m_pnext;pdel=pdel-m_pnext;)return 1;template Type SingleList if(n0) coutcant find the elementendl;exit (1);)ListNode *pmove=head,*pdel;for(int i=0;im_pnext;i+):Remove(int n)pmove=pmove-m_pnext;)if(pmove-m_pnext=NULL) coutcant find the elementm_pnext;pmove-m_pnext=pd
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据结构 各种 算法 实现 C+ 模板
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内