链表的c语言实现十.doc_第1页
链表的c语言实现十.doc_第2页
链表的c语言实现十.doc_第3页
链表的c语言实现十.doc_第4页
链表的c语言实现十.doc_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

在这里列举了一个应用单链表基本算法的综合程序,双向链表和循环链表的综合程序大家可以自己去试一试。#include #include #include #define N 10 typedef struct nodechar name20;struct node *link;stud;stud * creat(int n)stud *p,*h,*s;int i;if(h=(stud *)malloc(sizeof(stud)=NULL)printf(不能分配内存空间!);exit(0);h-name0=0;h-link=NULL;p=h;for(i=0;ilink=s;printf(请输入第%d个人的姓名,i+1);scanf(%s,s-name);s-link=NULL;p=s;return(h);stud * search(stud *h,char *x)stud *p;char *y;p=h-link;while(p!=NULL)y=p-name;if(strcmp(y,x)=0)return(p);else p=p-link;if(p=NULL)printf(没有查找到该数据!);stud * search2(stud *h,char *x)stud *p,*s;char *y;p=h-link;s=h;while(p!=NULL)y=p-name;if(strcmp(y,x)=0)return(s);elsep=p-link;s=s-link;if(p=NULL)printf(没有查找到该数据!);void insert(stud *p)char stuname20;stud *s;if(s= (stud *) malloc(sizeof(stud)=NULL)printf(不能分配内存空间!);exit(0);printf(n请输入你要插入的人的姓名:);scanf(%s,stuname);strcpy(s-name,stuname);s-link=p-link;p-link=s;void del(stud *x,stud *y)stud *s;s=y;x-link=y-link;free(s);void print(stud *h)stud *p;p=h-link;printf(数据信息为:n);while(p!=NULL)printf(%s ,&*(p-name);p=p-link;void quit()exit(0);void menu(void)clrscr();printf(ttt单链表C语言实现实例n);printf(tt|n);printf(tt| |n);printf(tt| 1 建 立 新 表 |n);printf(tt| 2 查 找 数 据 |n);printf(tt| 3 插 入 数 据 |n);printf(tt| 4 删 除 数 据 |n);printf(tt| 5 打 印 数 据 |n);printf(tt| 6 退 出 |n);printf(tt| |n);printf(tt| 如未建立新表,请先建立! |n);printf(tt| |n);printf(tt|n);printf(tt 请输入你的选项(1-6):);main()int choose;stud *head,*searchpoint,*forepoint;char fullname20;while(1)menu();scanf(%d,&choose);switch(choose)case 1:head=creat(N);break;case 2:printf(输入你所要查找的人的姓名:);scanf(%s,fullname);searchpoint=search(head,fullname);printf(你所查找的人的姓名为:%s,*&searchpoint-name);printf(n按回车键回到主菜单。);getchar();getchar();break;case 3: printf(输入你要在哪个人后面插入:);scanf(%s,fullname);searchpoint=search(head,fullname);printf(你所查找的人的姓名为:%s,*&searchpoint-name);insert(searchpoint);print(head);printf(n按回车键回到主菜单。);getchar();getchar();break;case 4:print(head);printf(n输入你所要删除的人的姓名:);scanf(%s,fullname);searchpoint=search(head,fullname);forepoint=search2(head,fullname);del(forepoint,searchpoint);break;case 5:print(head);printf(n按回车键回到主菜单。);getchar();getchar();break;case 6:quit();break;default:printf(

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论