设计一 顺序表的应用代码
Head.h
#define LIST_INIT_SIZE 100//线性表存储空间的初始分配量 #define LISTINCREMENT 10//线性表存储空间的分配增量 #define STACK_INIT_SIZE 100//栈存储空间初始分配量 #define STACKINCREMENT 10//栈存储空间分配增量 #define MAXQSIZE 10//最大队列长度 typedef int ElemType; typedef char SElemType; typedef int QElemType; typedef struct{ int *elem;//存储空间基址 int length;//当前长度 int listsize;//当前分配的存储容量 }SqList;
typedef struct{ SElemType *base;//在栈构造之前和销毁之后,base的值为null SElemType *top;//栈顶指针 int stacksize;//当前已分配的存储空间,以元素为单位 }SqStack; typedef struct { QElemType *base;//初始化的动态分配存储空间 int front;//头指针,若队列不空,指向队列头元素 int rear;//尾指针,若队列不空,指向队列尾元素的下一个位置 }SqQueue; void Check1(); void Check2(); void Check3(); void Check4();
int InitList_Sq(SqList *L); int CreateList(SqList *L);
int DeleteElem_Sq(SqList *L); int PrintElem(SqList L);
int DeleteElem_1(SqList *L);
int DevideList_Sq(SqList L,SqList *La,SqList *Lb); int InitStack(SqStack *L);
int Push(SqStack *S,SElemType e); int StackEmpty(SqStack S);
int GetTop(SqStack S,SElemType *e); int Pop(SqStack *S,SElemType *e); int Correct(char exp[], int n); int InitQueue(SqQueue *Q); int CreateQueue(SqQueue *Q);
1
int PrintQueue(SqQueue Q);
int EnQueue(SqQueue *Q,QElemType e); int DeQueue(SqQueue *Q,QElemType *e);
………………………………………………………………………………………………………. main.cpp
#include
………………………………………………………………………………………………………. Check1.cpp
#include \#include
2
DeleteElem_1(&L1); PrintElem(L1); }
CreateList.cpp #include\#include\#include\
//创建顺序表,在顺序表中输入数据元素。 int CreateList(SqList *L) { int i,n; if(!InitList_Sq(L))exit(-1); printf(\请输入顺序表的长度:\ scanf(\ (*L).length=n; ElemType *p=(*L).elem; printf(\请输入顺序表的数据元素:\ for(i=0;i PrintElem.cpp #include \#include DeleteElem_1.cpp #include \#include int DeleteElem_1(SqList *L) { int *p,*q,item; printf(\请输入要删去的元素:\ 3