欢迎来到天天文库
浏览记录
ID:57586367
大小:48.00 KB
页数:7页
时间:2020-08-27
《c++数据结构顺序表、单链表、查找的代码.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、顺序表#includeusingnamespacestd;templatevoidins_sq_LList(T*v,intm,int*n,inti,Tb){intk;if(*n==m){cout<<"overflow"<*n)i=*n+1;if(i<1)i=1;for(k=*n;k>=i;k--)v[k]=v[k-1];v[i-1]=b;*n=*n+1;return;}#includeusingnamespacestd;templatec
2、lasssq_LList{private:intmm;intnn;T*v;public:sq_LList(){mm=0;nn=0;return;}sq_LList(int);voidprt_sq_LList();intflag_sq_LList();voidins_sq_LList(int,T);voiddel_sq_LList(int);};templatesq_LList(T)::sq_LList(intm){mm=m;v=newT[mm];nn=0;return;}templatevoidsq_LList::
3、prt_sq_LList(){inti;cout<<"nn="<voidlinked_LList::ins_linked_LList(Tx,Tb){node*p,*q;p=newnode;p->d=b;if(head==null){head=p;p->next=null;return;}if(head->d==x){p->next=head;head=p;return;}q=head;while
4、((q->next!=NULL)&&(((q->next)->d)!=x))q=q->next;p->next=q->next;q->next=p;return;}linked_Llist.h#includeusingnamespacestd;templatestructnode{Td;node*next:};templateclasslinked_LList{private:node*head:public:linked_LList();voidprt_linked_LList();voidi
5、ns_linked_LList(T,T);intdel_linked_LList(T);};templatelinked_LList::linked_LList(){head=NULL;return;}templatevoidlinked_LList::prt_linked_LList(){node*p;p=head;if(p==NULL){cout<<"空链表!"<d<next;}while(p!=NULL);return;}#
6、includeusingnamespacestd;templatestructnode{Td;node*next:};//定义线性链表类templateclasslinked_LList{private:node*head:public:linked_LList();voidprt_linked_LList();voidins_linked_LList(T,T);intdel_linked_LList(T);};//建立空链表templatelinked_LList::li
7、nked_LList(){head=NULL;return;}//扫描输出链表中的元素templatevoidlinked_LList::prt_linked_LList(){node*p;p=head;if(p==NULL){cout<<"空链表!"<d<next;}while(p!=NULL);return;}templatevoidlinked_LList::ins_linked_LList(Tx,Tb){node*p
8、,*q;p=newnode;p->d=b;if(head==null){head=p;p
此文档下载收益归作者所有