线性表子系统-源代码_第1页
线性表子系统-源代码_第2页
线性表子系统-源代码_第3页
线性表子系统-源代码_第4页
线性表子系统-源代码_第5页
全文预览已结束

下载本文档

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

文档简介

1、精选优质文档-倾情为你奉上#include<stdio.h> typedef struct linknode char data; struct linknode *next; linnode; linnode *head; int n; void CreateList() n=0; linnode *p,*s; char x; int z=1; head=new linnode; p=head; printf("ntt请逐个输入结点,以“x”为结束标记!n"); printf("n"); while(z) printf("ntt输

2、入一个字符数据,并按回车:"); scanf("%c",&x); getchar(); if(x!='x') s=new linnode; n+; s->data=x; p->next=s; s->next=NULL; p=s; else z=0; void InsList(int i,char x) linnode *s,*p; p=head; int j=0; while(p!=NULL&&j<i) j+; p=p->next; if(p!=NULL) s=new linnode; s-&g

3、t;data=x; s->next=p->next; p->next=s; n+; else printf("ntt线行表为空或插入位置超出!n"); void DelList (char x)/删除结点元素 linnode *p,*q; if(head=NULL) printf("ntt链表下溢!"); return; if (head->next=NULL) printf("ntt线性表已经为空!"); return; q=head; p=head->next; while(p!=NULL&&

4、amp;p->data!=x) q=p; p=p->next; if(p!=NULL) q->next=p->next; delete p; n-; printf("ntt结点%c 已经被删除!",x); else printf("ntt抱歉!没有找到您要删除的结点。"); void ShowList()/显示线性表linnode *p=head; printf("ntt显示线性表的所有元素: "); if(head->next=NULL|p=NULL) printf("ntt链表为空!&quo

5、t;); else printf ("ntt"); while(p->next!=NULL) printf("%5c",p->next->data); p=p->next; void SearchList(char x)/查找线性表元素linnode *p; int i=1; if (head=NULL) printf("ntt链表下溢!"); return; if(head->next=NULL) printf("ntt线性表为空,没有任何结点!"); return; p=head-

6、>next; while(p!=NULL&&p->data!=x) p=p->next; i+; if(p!=NULL) printf("ntt在表的第%d 位置上找到值为%c 的结点!",i,x); else printf("ntt抱歉,未找到值为%c 的结点!",x); void main() head=NULL; int choice,i,j=1; char x; while(j) printf("n"); printf("ntt线性表子系统"); printf("

7、ntt*"); printf("ntt* 1-建表*"); printf("ntt* 2-插入*"); printf("ntt* 3-删除 *"); printf("ntt* 4-显示*"); printf("ntt* 5-查找*"); printf("ntt* 6-求表长*"); printf("ntt* 0-返回*"); printf("ntt*"); printf("ntt 请选择菜单号(0-6): "

8、;); scanf("%d",&choice); getchar(); if(choice=1) /用if语句实现菜单选择CreateList(); else if(choice=2) printf("ntt请输入插入的位置i和插入的数据(输入格式: i,x): "); scanf("%d,%c",&i,&x); InsList(i,x); else if(choice=3) printf("ntt请输入要删除的数值: "); scanf("%c",&x); DelList(x); else if(choice=4) if(head=NULL) printf("ntt请先建立线性表! "); else ShowList(); else if(choice=5) printf("ntt请输入要查找的元素: "); scanf("%c",&x); SearchL

温馨提示

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

评论

0/150

提交评论