线性表的操作建立一个含26个英文
顺序表操作代码如下:#includeconst int maxsize=1000;struct sequenlist{ char a[maxsize]; int len;};sequenlist setnull(sequenlist L){L。 len=0;return L;}sequenlist insert(sequenlist L,char x, int i){ int j; if(L。len>=maxsize-1) coutL。 len+1)) cout=i;j--) L。a[j+1]=L。a[j]; L。a[i]=x; L。len++; } return L;}...全部
顺序表操作代码如下:#includeconst int maxsize=1000;struct sequenlist{ char a[maxsize]; int len;};sequenlist setnull(sequenlist L){L。
len=0;return L;}sequenlist insert(sequenlist L,char x, int i){ int j; if(L。len>=maxsize-1) coutL。
len+1)) cout=i;j--) L。a[j+1]=L。a[j]; L。a[i]=x; L。len++; } return L;}sequenlist deletel(sequenlist L,int i){int j;if((iL。
len)) coutL。len)) return NULL;else return L。a [i];}void main(){sequenlist L;char x,y;int n;L=setnull(L);cout>n;for(int j=1;j>L。
a[j];L。len=n;print(L);cout>x>>j;L=insert(L,x,j);print(L);cout>j;L=deletel(L,j);print(L);cout>x;j=locate(L,x);if(j!=0)cout>x;cout>y;L=change(L,x,y);print(L);cout>j;x=get(L,j);coutclass link{public: char data; link *next;};class linklist{protected: link *head;public: link *hcreat() { link *s,*p; char i; cout>i; p=new link; p->next=NULL; while(i!='0') { s=new link; s->data=i; s->next=p->next; p->next=s; cin>>i; } return p; } void print(link *head) { link *p; p=head->next ; while(p->next!=NULL) { coutdata"; p=p->next; } coutdata ; coutnext ; while((p!=NULL)&&(p->data!=x)) p=p->next ; return p; } void deletel(link *head,char x) { link *p,*q; q=head; p=head->next; while((p!=NULL)&&(p->data!=x)) { q=p; p=p->next ; } if(p==NULL)coutnext =p->next ; delete(p); } } void insert(link *head,char x,char y) { link *p,*s; s=new link; s->data =y; if(head->next==NULL) { head->next=s; s->next=NULL; } p=Locate(head,x); if(p!=NULL) coutnext =p->next ; p->next ; } } void change(link *p,char x, char y) { link *q; q=p->next ; while(q!=NULL) { if(q->data==x)q->data=y; q=q->next ; } } int count(link *h) { link *p;int n=0; p=h->next ; while(p!=NULL) { n++; p=p->next ; } return n; }};void main(){int n;char x,y;link *p,*q;linklist a;p=a。
hcreat (); int(p);cout>y; letel (p,y); int (p);cout>x;cout>y; sert (p,x,y); int (p);cout>x>>y; ange (p,x,y); int (p);cout>x;q=a。
Locate (p,x);if(q==NULL)cout>i; p=r=new link; p->next=NULL; while(i!='0') { s=new link; s->data=i; r->next=s; r=s; cin>>i; } r->next=NULL; return p; }以上程序皆可以在vc 6 上运行。
收起