欢迎来到天天文库
浏览记录
ID:51686771
大小:46.45 KB
页数:7页
时间:2020-03-15
《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;templatecl
2、asssq_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::pr
3、t_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((q
4、->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();voidins_l
5、inked_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;}#inclu
6、deusingnamespacestd;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::linked_L
7、List(){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,*q;p=n
8、ewnode;p->d=b;if(head==null){head=p;p
此文档下载收益归作者所有