雙向循環(huán)鏈表_第1頁(yè)
雙向循環(huán)鏈表_第2頁(yè)
雙向循環(huán)鏈表_第3頁(yè)
雙向循環(huán)鏈表_第4頁(yè)
雙向循環(huán)鏈表_第5頁(yè)
已閱讀5頁(yè),還剩9頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、#include "stdlib.h"#include "stdio.h"#include "string.h"typedef struct list *LINK;LINK head;/*Í·Ö¸Õë,Á´±í¶¨Î»*/struct listint data;char name8;char tel12;int age;int scoure;struct list *front,*next;FIL

2、E *fp;main()char search(LINK p,char n);/*²éѯ*/LINK in_put(LINK p);/*ÊäÈ뺯Êý*/void output(LINK sp);/*Êä³ö*/int insert(LINK p2);/*²åÈë*/int del(LINK p2,int m);/*ɾ³ý*/void creat();

3、/*ÊäÈë²¢´´½¨Á´±í*/void read();/*¶ÁÈ¡ÎļþÄÚÈÝ*/void write_fp();/*дÈëÎļþ*/*/void exchange(LINK p1,LINK p2);/*Êý¾

4、21;½»»»*/LINK compare(LINK sp,char dn,char dm);/*±È½Ï*/LINK bts(LINK sp,LINK p1,LINK p2,char dm);/*´Ó´óµ½Ð¡ÅÅÁÐ*/LINK stb(LINK sp,LINK p1,LINK p2,char dm);/*´ÓСµ½´&

5、#243;ÅÅÁÐ*/*/char a;FILE *fp;LINK out_fp;int d,num,menu;/*menu²Ëµ¥¿ØÖƱäÁ¿*/if(fp=fopen("C:table.txt","r")=NULL)/*´ò¿ª»ò½¨Á¢Îļþ*/

6、printf("Can not open the file!nNow the program will build a new file!n");fp=fopen("C:table.txt","wt+");/*´ò¿ªÎļþ*/creat();/*´´½¨ÄÚÈÝ*/out_fp=head;dofprintf(fp,"%d %s %s %d %dn",ou

7、t_fp->data,out_fp->name,out_fp->tel,out_fp->age,out_fp->scoure);out_fp=out_fp->next;while(out_fp!=head);fclose(fp);/*¹Ø±ÕÎļþ*/elseread();/*¶ÁÈ¡Îļþ*/output(head);/*Êä³öÁ´&

8、#177;íÄÚÈÝ*/*/doprintf("/*Command menu list*/n1.Searchn2.Insertn3.Deleten4.Arrangementn0.Exitn");/*Ö÷²Ëµ¥Ñ¡Ï²éÕÒ£¬²åÈ룬ɾ³

9、3;£¬ÅÅÁУ¬Í˳ö*/doprintf("Please select an option:");a=getch();printf("%cn",a);if(a='1')break;else if(a='2')break;else if(a='3')break;else if(a='4')break;else if(a='0')exit(1);else

10、menu=1;while(menu);/*/if(a='4')dochar dm,dn;printf("Order of (1.name 2.scoure)?:");dm=getch();printf("%cn",dm);if(dm='1')|(dm='2')printf("Order from (1.big to small 2.small to big)?:");dn=getch();printf("%cn",dn);if(dn='1')|(dn=

11、'2')head=compare(head,dn,dm);else printf("Invalid Options!n");elseprintf("Invalid Options!n");output(head);/*/doprintf("Save to the file?(y/n):");a=getch();printf("%cn",a);if(a='y')write_fp();printf("Save complete!n");if(a='n'

12、)read();while(a!='y')&&(a!='n');/*/doprintf("Order again?(y/n):");a=getch();printf("%cn",a);if(a='y')num=1;if(a='n')num=0;menu=1;while(a!='y')&&(a!='n');while(num);output(head);read();/*/else if(a='1')doprint

13、f("Please enter the items you want to search:n(1.name 2.tel 3.age 4.scoure):Options:");/*fflush(stdin);/*Çå³ýIO»º³åÇø*/d=getch();printf("%cn",d);search(head,(char)d);doprintf("Search again?(y/n):");a=getch();printf("

14、;%cn",a);if(a='y')num=1;if(a='n')num=0;menu=1;while(a!='y')&&(a!='n');while(num);/*search*/output(head);/*/else if(a='2')dodoprintf("Insert data?(y/n):");a=getch();printf("%cn",a);if(a='y')num=insert(head);if(a='n&#

15、39;)num=0;menu=1;while(a!='y')&&(a!='n');while(num);output(head);/*/else if(a='3')doprintf("which number do you want to delete:NO.");d=getch();printf("%cn",d);num=del(head,d);output(head);doprintf("Delete again?(y/n):");a=getch();printf(&

16、quot;%cn",a);if(a='y')printf("which number do you want to delete:NO.");scanf("%d",&d);while(a=getchar()!='n'&&a!=EOF);/*Ë¢ÐÂÊäÈ뻺³åÇø*/num=del(head,d);output(head);if(a='n&

17、#39;)num=0;menu=1;while(a!='y')&&(a!='n');while(num);output(head);/*/else if(a='0')write_fp();menu=0;elsemenu=1;while(menu);exit(1);char search(LINK p,char n)/*²éѯ*/LINK a=p;char b9;int c;if(n='1')|(n='2')printf("Enter the con

18、tent:");scanf("%s",b);doif(strcmp(a->name,b)=0)|(strcmp(a->tel,b)=0)printf("%3d. |%8s|%15s|%8d|%8d|n",a->data,a->name,a->tel,a->age,a->scoure);return(0);elsea=a->next;while(a!=p);printf("No Datan");return(0);else if(n='3')|(n='4&

19、#39;)printf("Enter the content:");scanf("%d",&c);doif(a->age=c)|(a->scoure=c)printf("%3d. |%8s|%15s|%8d|%8d|n",a->data,a->name,a->tel,a->age,a->scoure);return(0);elsea=a->next;while(a!=p);printf("No Datan");return(0);elseprintf(&quo

20、t;Invalid Options!n");return(0);void output(LINK sp)/*Êä³öÁ´±í*/ int i;sp=head;printf(" n num | name | tel | age | scoure |n");for(i=1;i+)sp->data=i;/*×Ô¶¯±àºÅ*/printf("%3d. |%8s|%15s|%8d|%8d|n&quo

21、t;,sp->data,sp->name,sp->tel,sp->age,sp->scoure);sp=sp->next;if(sp=head)break;printf("n");int insert(LINK p2)/*²åÈëÁ´±í*/LINK sp,newnode;int i=0;sp=p2->front;newnode=(LINK)malloc(sizeof(struct list);if(newnode=NULL)printf("E

22、RRORn");return(1);in_put(newnode);newnode->next=sp->next;sp->next->front=newnode;newnode->front=sp;sp->next=newnode;/*²åÈëÁ´±í*/printf("insert complete!n");return(1);int del(LINK p2,int m)/*ɾ³ý½Ú&

23、#181;ã*/LINK sp;int a,i=0;sp=p2;doi+;sp=sp->next;while(sp!=head);if(m=1)head=head->next;if(1<m)&&(m<=i)for(a=1;a<m;a+)sp=sp->next;if(m>i)|(m<1)printf("out of ordern");return(1);sp->front->next=sp->next;sp->next->front=sp->front;/*Ö

24、;ØÐÂÁ¬½Ó½Úµã*/free(sp);/*ɾ³ý½Úµã*/printf("delete complete!n");return(0);void creat()/*´´½¨Á´±í*/LINK pb,newnode;int i;char a;for(i=0;i+)newnode=(LINK)mall

25、oc(sizeof(struct list);doprintf("n");newnode->data=i+1;in_put(newnode);printf(" num | name | tel | age | scoure |n");printf("%3d. |%8s|%15s|%8d|%8d|n",newnode->data,newnode->name,newnode->tel,newnode->age,newnode->scoure);printf("sure?(press '

26、y' to continue):");/*·ÀÖ¹ÊäÈë´íÎó*/while(a=getch()!='y');if(i=0)pb=head=newnode;head->front=NULL;head->next=NULL;/*Ë«Ïò½Úµã³õʼ»¯*/elsepb->next=

27、newnode;/*½¨Á¢½ÚµãÁ¬½Ó*/newnode->front=pb;newnode->next=NULL;pb=newnode;printf("nInsert again?(press 'y' to continue):");if(a=getch()='y')continue;elsebreak;head->front=newnode;pb->next=head;/*Ë

28、71;Ñ­»·Á´±í½¨Á¢Íê±Ï*/void read()/*¶ÁÈ¡Îļþ*/LINK pb,newnode;FILE *fp;int i;/*numÁ´±í²åÈë¿ØÖÆ*/fp=fopen("C:table.txt

29、","r");for(i=0;i+)newnode=(LINK)malloc(sizeof(struct list);fscanf(fp,"%d %s %s %d %dn",&newnode->data,&newnode->name,&newnode->tel,&newnode->age,&newnode->scoure);if(i=0)pb=head=newnode;head->front=NULL;head->next=NULL;/*Ë«&

30、#207;ò½Úµã³õʼ»¯*/else pb->next=newnode;/*½¨Á¢½ÚµãÁ¬½Ó*/newnode->front=pb;newnode->next=NULL;pb=newnode;if(feof(fp)break; head->front=newnode;pb->next=head;/*Ë«

31、Ñ­»·Á´±í½¨Á¢Íê±Ï*/fclose(fp); void write_fp()/*дÈëÎļþ*/LINK out_fp;if(fp=fopen("C:table.txt","r")=NULL)/*дÈëÎļþ*/pri

32、ntf("Can not open the file!nNow the program will build a new file!n");fp=fopen("C:table.txt","wt+");out_fp=head;dofprintf(fp,"%d %s %s %d %dn",out_fp->data,out_fp->name,out_fp->tel,out_fp->age,out_fp->scoure);out_fp=out_fp->next;while(out_fp!

33、=head);fclose(fp);elsefp=fopen("C:table.txt","wt+");out_fp=head;dofprintf(fp,"%d %s %s %d %dn",out_fp->data,out_fp->name,out_fp->tel,out_fp->age,out_fp->scoure);out_fp=out_fp->next;while(out_fp!=head);fclose(fp);LINK in_put(LINK p)/*ÊäÈ&

34、#235;º¯Êý*/printf("please input the name:");scanf("%s",&p->name);printf("please input the tel:");scanf("%s",&p->tel);printf("please input the age:");scanf("%d",&p->age);printf("please input the

35、scoure:");scanf("%d",&p->scoure);return(p);/*/LINK compare(LINK sp,char dn,char dm)LINK p1,p2,p0;p1=p0=sp;p2=p1->next;if(dn='1')if(dm='1')for(;p2!=sp;p2=p2->next)if(strcmp(p2->name,p1->name)>0)p1=p2;sp=p1;p0=sp;for(;(p0->next->next)!=sp;p0=p0->next)p1=p0->next;p2=p1->next;

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論