试验一:线性表的设计与实现.docx

  1. 1、本文档共4页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
PAGE 3 计算机软件基础实验报告 钟鑫 通过本次实验,加深了对c语言的理解。提高了自身阅读样本程序、调试程序的能力。 一、/* 线性表的程序设计shiyan11.c */ #include stdio.h /*编译预处理命令*/ #include conio.h #define Null 0 #define MaxSize 1024 /*定义数据域最大长度*/ typedef int DataType; typedef struct node { /*定义线性链表*/ DataType data[MaxSize]; int last; } SequenList; void PrintOut(SequenList *L); int Delete(SequenList *L,int i); void CreateList(SequenList *L); int Insert(SequenList *L,DataType x,int i);/*在主函数外先声明此函数,否则后面的函数无法正常使用*/ int main() { /*主函数*/ SequenList MyList,*L; char cmd; int i,t,x; L=MyList; L-last=-1; do { do { clrscr(); /*在c++的环境下不需要此函数所以直接删除即可*/ printf(\n\tc,CCreate List\n); /*首先建立主菜单*/ printf(\n\ti,I Insert); printf(\n\td,DDelete); printf(\n\tq,QQuit\n\tYour choice:); cmd=getchar(); }while((cmd!=d)(cmd!=D)(cmd!=q)(cmd!=Q)(cmd!=i)(cmd!=I)(cmd !=c)(cmd !=C)); /* or: while((toupper(cmd)!=’D’)(toupper(cmd)!=’Q’) (toupper(cmd)!=’I’)(toupper(cmd)!=’C’)); */ switch(cmd) { /*建立分支结构,实现引导功能*/ case c: case C:CreateList(L); break; case i: case I:printf(\nInput the data to be inserted:); /* 插入元素到指定 scanf(%d,x); 位置 */ printf(\nInput the poistion to be inserted:); printf(\n(1--%d)\n,(L-last+2)); scanf(%d,i); Insert(L,x,i); /*函数应先声明再调用*/ PrintOut(L); getch(); break; case d: case D:printf(\nInput the index_No of data to be deleted\n); printf(\n(1%d):\n,(L-last+1)); /* 删出指定位置的元素 */ scanf(%d,i); Delete(L,i); PrintOut(L); getch(); break; default: break; } } while((cmd!=q) (cmd!=Q)); /* or: while((toupper(cmd)!=Q)); */ return Null; /*定义的主函数需要一个返回值,表示结束main()的运行,作为程序的结束状态。因之前以将Null赋值为0,因此可直接返回Null.*/ } /*以下为定义插入函数,先将要插入位置后的每个数据往后挪一位,再将要插入的数据放入链表中。*/ int Insert(SequenList *L,DataType x,int i) { /*前面没有声明

文档评论(0)

zhuliyan1314 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档