- 9
- 0
- 约6.95千字
- 约 14页
- 2017-01-12 发布于江苏
- 举报
线性表的c
线性表的数组表示及其实现:C++表示
//线性表的应用linelist1m.cpp本程序elem表示数据类型为结构体ElemType的数组.首先给出了线性表的类定义,然后给出线性表中原形的实现部分最后是对线性表中的主要操作进行了测试并输出结果
其中,对线性表按升序或降序输出printlist(int mark)函数的形参mark为标志符mark==0为对线性表无序输出;mark==1为对线性表升序输出;mark==-1为对线性表降序输出;
//线性表的应用linelist1m.cpp
#includeiostream.h#includeiomanip.h#includemalloc.h#includestring.h#include linelist1.cppvoid main(){ coutlinelist1m.cpp运行结果:\n;? ElemType e,e1,e2,e3,e4,e5,e6;? List *La,*Lb,*Lc;? int k;? cout首先调用插入函数.\n;? La-init(La,4);? strcpy(e1.name,stu1);? strcpy(e1.stuno,100001);? e1.age=22;? e1.score=88;? La-ListInsert(1,e1);? strcpy(e2.name,stu2);? strcpy(e2.stuno,100002);? e2.age=21;? e2.score=79;? La-ListInsert(2,e2);? strcpy(e3.name,stu3);? strcpy(e3.stuno,100003);? e3.age=19;? e3.score=87;? La-ListInsert(3,e3);? La-printlist(0);? cout表La长:La-ListLength()endl;? cin.get();
? Lb-init(Lb,4);? strcpy(e4.name,zmofun);? strcpy(e4.stuno,100001);? e4.age=20;? e4.score=94;? Lb-ListInsert(1,e4);? strcpy(e5.name,bobjin);? strcpy(e5.stuno,100002);? e5.age=23;? e5.score=69;? Lb-ListInsert(2,e5);? strcpy(e6.name,stu1);? strcpy(e6.stuno,100001);? e6.age=22;? e6.score=88;? Lb-ListInsert(3,e6);? Lb-printlist(0);? cout表Lb长:Lb-ListLength()endl;? cin.get();
? cout表La与Lb合并为表Lc:\n;? Lc-init(Lc,6);? Lc-MergeList(La,Lb);? Lc-printlist(0);? cout表Lc长:Lc-ListLength()endl;? cin.get();
? cout表La与Lb联合为表La:\n;? La-UnionList(La,Lb);? La-printlist(0);? cout表La长:La-ListLength()endl;? cin.get();
? k=Lc-ListDelete(-1,e6);? if(k==0) cout删除失败!\n;? else cout删除成功!\n;? cout输出表Lc:\n;? Lc-printlist(0);? cin.get();? strcpy(e.name,NoName);? La-PriorElem(e2,e);? if(strcmp(e.name,NoName)==0) coute2无前驱!\n;? else coute2的前驱e.name=e.nameendl;? strcpy(e.name,NoName);? La-NextElem(e3,e);? if(strcmp(e.name,NoName)==0) coute3无后继!\n;? else coute3的后继e.name=e.nameendl;? cin.get();? cout按成绩升序输出表Lc\n;? Lc-printlist(1);cin.get();? cout按成绩降序输出表Lc\n;? Lc-printlist(-1);cin.get();}
?
线性表的类定义
//线性表的类定义linelist1.h
原创力文档

文档评论(0)