1、1.这是 p1list.h 自定义的头文件/-Head files for list in chapter 2 -#include #include #include /预定义常量#define TRUE 1#define FALSE 0#define OK 1#define ERROR 0#define INFEASIBLE -1#define OVERFLOW-2#define GUARD -99#define MAXLEN 255 /线性表(顺序表)的最大长度#define LIST_MAX_SIZE 50 /链表的最大长度/函数结果的类型typedef int Status;typed
2、ef int ElemType;typedef struct ElemType *elem;int length;int listsize; SqList;typedef struct List int elemMAXLEN;int length; List;typedef unsigned char SStringMAXLEN + 1;typedef int ElemType;typedef struct LNode int data;struct LNode *next;LNode, *LinkList;/- p1list.cpp -void InitList(List /* 此函数用于初
3、始化一个保持增序的线性表 Lvoid InitList0(List /* 此函数用于初始化一个线性表 Lvoid printList(List L);void createTwoLists(List void MergeList(List La, List Lb, List /*TBD1* 将 Lb 归并到 La 表,形成新表 Lcvoid Union(List /*TBD2* 线性 La 和 Lb 分别表示两个集合,求新集合 LaLa U Lb( U“并“操作)void ReverseList(List /*TBD3* 将线性表 L 逆转void deleteall(List /*TBD4*
4、 从一给定的顺序表 L 中删除元素值在 x 和 y 之间的所有元素(x MAXLEN) Lb.length=MAXLEN-La.length; /*TBD1* 将 Lb 归并到 La 表,形成新表 Lc*TBD1* 要求 L0.c 保持有序,允许出现重复元素*TBD1*/void MergeList(List La, List Lb, List while(i=Lb.elemj)Lc.elemm+=Lb.elemj+;else Lc.elemm+=La.elemi+; while(i=i+1)La.elemt=La.elemt-1;t-;La.elemi+=Lb.elemj+;t=+La.le
5、ngth;while(jy) /机智啊把对的重新放一遍 ;L.elemn+=L.elemi;L.length=n;int main(int argc, char* argv) List La,Lb,Lc;int x,y,n,h;int j;while(1)printf(“n1-创建数组 La,Lb,2-合并数组 La,Lb 到 Lc,含重复元素 3-归并 Lb 到La,不重复n“);printf(“4-逆转数组,5-删除数组中 x-y 之间的值 6-遍历 La,7-遍历 Lb,n“); printf(“输入大于 7 的数退出 n“);scanf(“%d“,/ system(“cls“); /盖
6、住啦。 。switch(h)case 1: createTwoLists(La,Lb);break;case 2: MergeList(La,Lb,Lc); printList(Lc);break;case 3: Union(La,Lb);printList(La);break;case 4:printf(“逆转数组 1-La 或 2-Lb“);scanf(“%d“,if(j=1)ReverseList(La);printList(La);elseReverseList(Lb);printList(Lb);break;case 5:printf(“输入 x,y,顺序表 L 中删除元素值在 x 和 y 之间的所有元素 (x7)break;/mainlottery();printf(“n 键入任意字符程序退出 “); getchar();return 0;