ImageVerifierCode 换一换
格式:DOCX , 页数:16 ,大小:15.88KB ,
资源ID:9778333      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/9778333.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(单链表的创建插入删除以及读取记录.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

单链表的创建插入删除以及读取记录.docx

1、单链表的创建插入删除以及读取记录#include#include#include#includeint n,id;/int fd;FILE *fp;struct student long num; int age; float score; struct student *next;struct student *head;/struct student *f,*sp;struct student *create() struct student *p,*q; n=0,head=NULL; p=(struct student *)malloc(sizeof(struct student); q

2、=(struct student *)malloc(sizeof(struct student); printf(please input the records:n); scanf(%ld %d %f,&q-num,&q-age,&q-score); if(q-num!=0) if(fp=fopen(/home/linux/shiyan/listfile.c,ab+)=NULL) printf(can not open the file.n); return; if(fwrite(q,sizeof(struct student),1,fp)!=1) printf(can not write

3、file!n); printf(ok!n); fclose(fp); else printf(over write records into file.n); while(q-num!=0) n+=1; if(n=1) head=q; else p-next=q; p=q; q=(struct student *)malloc(sizeof(struct student); printf(please input more records:n); scanf(%ld %d %f,&q-num,&q-age,&q-score); if(q-num!=0) if(fp=fopen(/home/li

4、nux/shiyan/listfile.c,ab+)=NULL) printf(can not open the file.n); return; if(fwrite(q,sizeof(struct student),1,fp)!=1) printf(can not write file!n); printf(ok!n); fclose(fp); else printf(over write records into file.n); p-next=NULL; return head;void print() struct student *l; printf(the numbers of l

5、ist are:%dn,n); l=head; if(head!=NULL) do printf(num:%ld age:%d score:%.1fn,l-num,l-age,l-score); l=l-next; while(l!=NULL); else printf(the list is null.n); struct student *insert() struct student *e,*t,*x,*into; t=head; printf(please input the insert record:n); into=(struct student *)malloc(sizeof(

6、struct student); scanf(%ld %d %f,&into-num,&into-age,&into-score); if(into-num!=0) if(fp=fopen(/home/linux/shiyan/listfile.c,ab+)=NULL) printf(can not open the file.n); return; if(fwrite(into,sizeof(struct student),1,fp)!=1) printf(can not write file!n); printf(ok!n); fclose(fp); else printf(over wr

7、ite records into file.n); while(into-num!=0) e=into; if(head=NULL) head=e; e-next=NULL; else while(e-numt-num)&t-next!=NULL) x=t; t=t-next; if(e-numnum) if(t=head) head=e; e-next=t; else x-next=e; e-next=t; else t-next=e; e-next=NULL; n+=1; printf(please input the insert record:n); into=(struct stud

8、ent *)malloc(sizeof(struct student); scanf(%ld %d %f,&into-num,&into-age,&into-score); if(into-num!=0) if(fp=fopen(/home/linux/shiyan/listfile.c,ab+)=NULL) printf(can not open the file.n); return; if(fwrite(into,sizeof(struct student),1,fp)!=1) printf(can not write file!n); printf(ok!n); fclose(fp);

9、 else printf(over write records into file.n); return head;struct student *delete() struct student *s,*c; long num; printf(please input the delete record:n); scanf(%ld,&num); while(num!=0) if(head=NULL) printf(the list is null.n); return head; s=head; while(num!=s-num)&(s-next!=NULL) c=s; s=s-next; i

10、f(num=s-num) if(s=head) head=s-next; free(s); else c-next=s-next; s=s-next; free(s); printf(delete %ld is success.n,num); n-=1; else printf(can not found %ldn,num); printf(please input the delete record:n); scanf(%ld,&num); return head;struct student *refer() struct student *r,*m; long rnum; printf(

11、please input to refer num:n); scanf(%ld,&rnum); r=head; if(rnum!=0) while(m-next!=NULL&r-num!=rnum) m=r; r=m-next; if(m-next=NULL) printf(the record is not exist.n); return head; if(rnum=r-num) printf(the record find:n); printf(num:%ld age:%d score:%.1fn,r-num,r-age,r-score); else printf(the inputer

12、 is error.n); return head;/*struct student *save() FILE *fp; struct student *l1; if(fp=fopen(/home/linux/shiyan/listx,ab+)=NULL) printf(can not open the file.n); return; l1=head; for(id=0;idnum,f1-age,f1-score);/sp=(struct student *)malloc(sizeof(struct student); / f1=f1-next; n+=1; fclose(fp); retu

13、rn f1;/*void load() fd=open(/home/linux/shiyan/list.txt,O_RDONLY); for(id=0;idnum,f-age,f-score); f=f-next; buffer=f; close(fd);*/*void save() fd=open(/home/linux/shiyan/list.txt,O_WRONLY|O_CREAT); for(id=0;idnext; close(fd);*/int choose() int choice; scanf(%d,&choice); return choice;void selecte(in

14、t number) / head=create(); / struct student *head; switch(number) case 1: insert(); break; case 2: delete(); break; case 3: print(); break; case 4: load(); break; case 5: refer(); break; / case 6: / save(); / break; case 6: exit(0); default: printf(the choice is not lawful,please input againn); brea

15、k; void menu() printf(=THE MAIN MENU=n); printf(1:insert a record in list.n); printf(2:delete a record from list.n); printf(3:printf present records on screen.n); printf(4:read the records from listfile.c.n); printf(5:select the record from list.n); printf(6:get away the main menu.n); printf(=n); pr

16、intf(please input a choice:1-2-3-4-5-6n); selecte(choose();/*void save() FILE *fp; if(fp=fopen(list.txt,w)=NULL) printf(can not open file!n); return; for(id=0;idnext; fclose(fp);*/*void load() FILE *fp; if(fp=fopen(list.txt,r=NULL) printf(can not open file!n); return; for(id=0;idnum,head-age,head-sc

17、ore); head=head-next; fclose(fp);*/int main() / printf(please input the records:n); / h=create(); / print(h); /* printf(please input the insert record:n); into=(struct student *)malloc(sizeof(struct student); scanf(%ld %d %f,&into-num,&into-age,&into-score); while(into-num!=0) h=insert(h,into); prin

18、t(h); printf(please input the insert record:n); into=(struct student *)malloc(sizeof(struct student);scanf(%ld %d %f,&into-num,&into-age,&into-score); printf(please input the delete record:n); scanf(%ld,&dnum); while(dnum!=0) h=delete(h,dnum); print(h); printf(please input the delete record:n); scanf(%ld,&dnum); */ head=create(); while(1) menu(); return EXIT_SUCCESS;

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1