=MAX)return(0);if(i<1||i>n+1)return(0"> =MAX)return(0);if(i<1||i>n+1)return(0" />
欢迎来到天天文库
浏览记录
ID:55529935
大小:29.50 KB
页数:10页
时间:2020-05-16
《数据结构 级程序一(C语言).doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、程序一:顺序表的运算#defineMAX100#include"stdio.h"intn;intinsert(intb[],intx,inti){intj;if(n>=MAX)return(0);if(i<1
2、
3、i>n+1)return(0);else{for(j=n;j>=i;j--)b[j]=b[j-1];b[j]=x;n++;return(1);}}intdelete(intb[],inti){intj;if(n==0)return(0);if(i<1
4、
5、i>n)return(0);else{for(j=i;j6、oidquit(){exit(0);}voidprint(intb[]){intj;printf("");for(j=0;j7、seselect(1-3):");scanf("%d",&sel);switch(sel){case1:printf("Pleaseinputtheinsertednumber:");scanf("%d",&x);printf("Pleaseinputtheinsert-location:");scanf("%d",&i);result=insert(a,x,i);if(result==1){printf("Theresultafterinsert:");print(a);}break;case2:printf("Pleaseinputtheindexofdelete:");sc8、anf("%d",&i);result=delete(a,i);if(result==1){printf("Theresultafterdelete:");print(a);}break;case3:quit();break;default:printf("INPUTSELECTERROR!PlEASERETRY!");}}}程序二:单链表的运算#include"stdio.h"#include"stdlib.h"structlink{intdata;structlink*next;};typedefstructlinkNODE;NODE*rcreat(){NODE*9、p,*r,*s;inti;s=(NODE*)malloc(sizeof(NODE));p=s;r=s;s->next=NULL;printf("Pleaseinputdata:");scanf("%d",&i);while(i){s=(NODE*)malloc(sizeof(NODE));s->data=i;r->next=s;r=s;printf("Pleaseinputdata:");scanf("%d",&i);}r->next=NULL;return(p);}voidprint(NODE*head){NODE*p;p=head->next;while(p){print10、f("%5d",p->data);p=p->next;}}voidinsert(NODE*head,intx,inti){NODE*p,*s;intcount=0;p=head;while(countnext;count++;}s=(NODE*)malloc(sizeof(NODE));s->data=x;s->next=p->next;p->next=s;}intdelete(NODE*head,inti){NODE*p=head,*q;intcount=0;intdel_data;if(head->next==NULL)return(0);else{while(11、countnext;count++;}q=p->next;p=q->next;del_data=q->data;free(q);return(del_data);}}main(){NODE*head;intc,x,i,d;head=rcreat();printf("Scaningresult:");print(head);while(1){printf("**********************
6、oidquit(){exit(0);}voidprint(intb[]){intj;printf("");for(j=0;j7、seselect(1-3):");scanf("%d",&sel);switch(sel){case1:printf("Pleaseinputtheinsertednumber:");scanf("%d",&x);printf("Pleaseinputtheinsert-location:");scanf("%d",&i);result=insert(a,x,i);if(result==1){printf("Theresultafterinsert:");print(a);}break;case2:printf("Pleaseinputtheindexofdelete:");sc8、anf("%d",&i);result=delete(a,i);if(result==1){printf("Theresultafterdelete:");print(a);}break;case3:quit();break;default:printf("INPUTSELECTERROR!PlEASERETRY!");}}}程序二:单链表的运算#include"stdio.h"#include"stdlib.h"structlink{intdata;structlink*next;};typedefstructlinkNODE;NODE*rcreat(){NODE*9、p,*r,*s;inti;s=(NODE*)malloc(sizeof(NODE));p=s;r=s;s->next=NULL;printf("Pleaseinputdata:");scanf("%d",&i);while(i){s=(NODE*)malloc(sizeof(NODE));s->data=i;r->next=s;r=s;printf("Pleaseinputdata:");scanf("%d",&i);}r->next=NULL;return(p);}voidprint(NODE*head){NODE*p;p=head->next;while(p){print10、f("%5d",p->data);p=p->next;}}voidinsert(NODE*head,intx,inti){NODE*p,*s;intcount=0;p=head;while(countnext;count++;}s=(NODE*)malloc(sizeof(NODE));s->data=x;s->next=p->next;p->next=s;}intdelete(NODE*head,inti){NODE*p=head,*q;intcount=0;intdel_data;if(head->next==NULL)return(0);else{while(11、countnext;count++;}q=p->next;p=q->next;del_data=q->data;free(q);return(del_data);}}main(){NODE*head;intc,x,i,d;head=rcreat();printf("Scaningresult:");print(head);while(1){printf("**********************
7、seselect(1-3):");scanf("%d",&sel);switch(sel){case1:printf("Pleaseinputtheinsertednumber:");scanf("%d",&x);printf("Pleaseinputtheinsert-location:");scanf("%d",&i);result=insert(a,x,i);if(result==1){printf("Theresultafterinsert:");print(a);}break;case2:printf("Pleaseinputtheindexofdelete:");sc
8、anf("%d",&i);result=delete(a,i);if(result==1){printf("Theresultafterdelete:");print(a);}break;case3:quit();break;default:printf("INPUTSELECTERROR!PlEASERETRY!");}}}程序二:单链表的运算#include"stdio.h"#include"stdlib.h"structlink{intdata;structlink*next;};typedefstructlinkNODE;NODE*rcreat(){NODE*
9、p,*r,*s;inti;s=(NODE*)malloc(sizeof(NODE));p=s;r=s;s->next=NULL;printf("Pleaseinputdata:");scanf("%d",&i);while(i){s=(NODE*)malloc(sizeof(NODE));s->data=i;r->next=s;r=s;printf("Pleaseinputdata:");scanf("%d",&i);}r->next=NULL;return(p);}voidprint(NODE*head){NODE*p;p=head->next;while(p){print
10、f("%5d",p->data);p=p->next;}}voidinsert(NODE*head,intx,inti){NODE*p,*s;intcount=0;p=head;while(countnext;count++;}s=(NODE*)malloc(sizeof(NODE));s->data=x;s->next=p->next;p->next=s;}intdelete(NODE*head,inti){NODE*p=head,*q;intcount=0;intdel_data;if(head->next==NULL)return(0);else{while(
11、countnext;count++;}q=p->next;p=q->next;del_data=q->data;free(q);return(del_data);}}main(){NODE*head;intc,x,i,d;head=rcreat();printf("Scaningresult:");print(head);while(1){printf("**********************
此文档下载收益归作者所有