语言最经典的链表呢
民生娱乐 2021-08-24 13:31 字号: 大 中 小
在turbo c 2.0 下调试通过.(把汉语注释去掉) #include\"stdio.h\"#include\"malloc.h\"#define NULL 0#define L sizeof(struct integer)struct integer /*定义结构体*/{int num;int zhengshu; struct integer *next;};int n; //纪录链表的长度struct integer *creat(void) /*创建链表*/{ struct integer *head; struct integer *p1,*p2; n=0; p1=p2=(struct integer *)malloc(L); scanf(\"%d,%d\",p1-num,p1-zhengshu); head=NULL; while(p1-num!=0){n=n+1; if(n==1) head=p1; else p2-next=p1; p2=p1; p1=(struct integer *)malloc(L); scanf(\"%d,%d\",p1-num,p1-zhengshu);} p2-next=NULL; return(head);}void print(struct integer *head) /*打印链表中的数据*/{ struct integer *p; printf(\"Now %d biaohao and zhengshu are :n\",n); p=head; if(head!=NULL) do {printf(\"%d,%5.1dn\",p-num,p-zhengshu); p=p-next; }while(p!=NULL);}int count(struct integer *head) /*返回链表的长度*/{int i=0; struct integer *p;p=head;while(p!=NULL){p=p-next;i++;}return i;}void *findnode(struct integer *head,int num) /*查找链表中的第num个数据*/{int j=1;struct integer *p;/*if(head==NULL){printf(\"n空链表,请先创建!n\");return;}*/p=head;if(numcount(head)||num=0){printf(\"Input error! Please input againn\");}else{while(p!=NULL jnext;}printf(\"%d bianhao reprensts %dn\",p-num,p-zhengshu);printf(\"n\");}return(head);}struct integer *del(struct integer *head,long num) /*删除链表中的第num个数据*/{struct integer *p1,*p2; if(head==NULL){printf(\"nList Null!n\"); return;} p1=head; while(num!=p1-num p1-next!=NULL){ p2=p1; p1=p1-next;} if(num==p1-num) { if(p1==head) head=p1-next; else p2-next=p1-next; printf(\"Delete: %dn\",num); n=n-1; } else printf(\"%d not been fonnd!n\",num); return(head);}struct integer *insert(struct integer *head,struct integer *stud) /*插入数据*/{ struct integer *p0,*p1,*p2; p1=head; p0=stud; if(head==NULL){head=p0; p0-next=NULL;} else{while((p0-nump1-num)(p1-next!=NULL)){p2=p1; p1=p1-next;}if(p0-num=p1-num){ if(head==p1)head=p0; else p2-next=p0; p0-next=p1;} else{ p1-next=p0; p0-next=NULL;}} n=n+1; return(head);}main() /*主功能函数*/{int a,b; struct integer *head,stu; int del_num,fin_num;printf(\"1 to go on / 0 to exit:n\");scanf(\"%d\",a);while(a!=0){/*struct integer *head,stu; int del_num;*/printf(\"1 creat 2 print 3 delete 4 insert 5 findonde 0 exitn\");/*菜单的实现*/scanf(\"%d\",b);switch(b){case 1:{/*clrscr();*/printf(\"Please Input bianhao and data:n\");printf(\"for example 1,90 0,0 to exit:n\");head=creat();}break;case 2:{/*clrscr();*/print(head);}break;case 3:{/*clrscr();*/ printf(\"nInput the deleted biaohao:\"); scanf(\"%d\",del_num); head=del(head,del_num);}break; case 4:{/*clrscr();*/ printf(\"nInput the inserted biaohao and zhengshu:\"); scanf(\"%d,%d\",m,engshu); head=insert(head,stu);}break; case 5:{/*clrscr();*/printf(\"Please Input the bianhao you want to find:\");scanf(\"%d\",fin_num);head=findnode(head,fin_num);}break;case 0:{ return;}break;default:printf(\"Input error! Please input againn\");}} }
全国财政收入47507亿元 查看本文来源
类风湿性关节炎长期治疗吃什么药好周口治疗白癜风医院费用
定制门窗去哪里好
-
-
恩惠深度吞下万帮火箭拿下甜瓜老鹰图的啥
深度|吞下万帮火箭拿下甜瓜 老鹰图的啥?安东尼随着老鹰买...
2020-09-14 | 民生娱乐
-
-
英媒克洛普将不会被禁赛口头警告罚款榜搭配
英媒:克洛普将不会被禁赛 口头警告+罚款榜克洛普直播吧12月...
2020-06-07 | 民生娱乐
-
-
中国房地产市场泡沫的存在是不争的事实搭配
中国房地产市场泡沫的存在是不争的事实自4月14日国务院调控...
2020-06-06 | 民生娱乐
-
-
NBA大富豪老板最壕是他灰熊老板帅出天际搭配
NBA大富豪老板:最壕是他!灰熊老板帅出天际NBA老板们北京时间...
2020-05-31 | 民生娱乐
-
-
阿根廷主帅意甲两神锋还有戏之前也招过他们搭配
阿根廷主帅:意甲两神锋还有戏 之前也招过他们桑保利表示迪...
2020-05-29 | 民生娱乐
-
-
7月海南新房均价环比下跌后市房价仍将小幅搭配
7月海南新房均价环比下跌 后市房价仍将小幅下调数据显示,...
2020-05-28 | 民生娱乐