{ case ')':if(e=='(')Pop(&S,&x);else return 0;break; case ']':if(e=='[')Pop(&S,&x);else return 0;break; case '}':if(e=='{')Pop(&S,&x);else return 0;break; } } } if(!StackEmpty(S))return 0; else return 1; }
GetTop.cpp
#include \
int GetTop(SqStack S,SElemType *e)
{//若栈不空,则用e返回S的栈顶元素,并返回1,否则返回0 if(S.top==S.base)return 0; else *e=*(S.top-1); return 1; }
InitStack.cpp
#include
int InitStack(SqStack *S) { (*S).base=(SElemType *)malloc(STACK_INIT_SIZE*sizeof(SElemType)); if(!(*S).base)exit(-1);//存储分配失败 (*S).top=(*S).base; (*S).stacksize=STACK_INIT_SIZE; return 1; }
Pop.cpp
#include \
int Pop(SqStack *S,SElemType *e)
{//若栈不空,则删除S的栈顶元素,用e返回其值,并返回1,否则返回0 if(StackEmpty(*S))return 0; *e=*(--(*S).top); return 1; }
Push.cpp
#include
int Push(SqStack *S,SElemType e)
6
{//插入元素e为新的栈顶元素 if((*S).top-(*S).base>=(*S).stacksize)//栈满,追加存储空间 { (*S).base=(SElemType
*)realloc((*S).base,((*S).stacksize+STACKINCREMENT)*sizeof(SElemType)); if(!(*S).base)exit(-1);//存储分配失败 (*S).stacksize+=STACKINCREMENT; } *((*S).top++)=e; return 1; }
StackEmpty.cpp #include \
int StackEmpty(SqStack S) { if(S.top==S.base)return 1; else return 0; }
………………………………………………………………………………………………………. Check4().cpp #include \#include
CreateQueue.cpp #include
7
InitQueue(Q); printf(\输入队列的长度 :\ scanf(\ if(n>MAXQSIZE){printf(\ for(i=0;i DeQueue.cpp #include \#include int DeQueue(SqQueue *Q,QElemType *e) {//若队列不空,则删除Q的队头元素,用e返回其值,并返回1,否则返回0 if((*Q).front==(*Q).rear){printf(\ *e=(*Q).base[(*Q).front]; (*Q).front=((*Q).front+1)%MAXQSIZE; return 1; } EnQueue.cpp #include int EnQueue(SqQueue *Q,QElemType e) {//插入元素e为新的队尾元素 if(((*Q).rear+1)%MAXQSIZE==(*Q).front){printf(\队列满 ((*Q).base)[(*Q).rear]=e; (*Q).rear=((*Q).rear+1)%MAXQSIZE; return 1; } InitQueue.cpp #include \#include int InitQueue(SqQueue *Q) { (*Q).base=(QElemType *)malloc(MAXQSIZE*sizeof(QElemType)); if(!((*Q).base))exit(-1);//存储空间分配失败 (*Q).front=(*Q).rear=0; return 1; } PrintQueue.cpp #include \ 8 #include int PrintQueue(SqQueue Q) { if(Q.front==Q.rear){printf(\ int i,n; QElemType *p; n=(Q.rear-Q.front+MAXQSIZE)%MAXQSIZE; p=&((Q.base))[Q.front]; for(i=0;i ………………………………………………………………………………………………………. 设计二链表的应用代码 Head.h typedef int ElemType; typedef struct LNode {//线性表的单链表存储结构 ElemType data; struct LNode *next; }LNode,*LinkList; typedef struct DuLNode{ //线性表的双向链表存储结构 ElemType data; struct DuLNode *prior; struct DuLNode *next; int freq; }DulNode,*DuLinkList; void CreateList_L(LinkList *L,int n); int PrintLinkList(LinkList L); int EqualLinkList(LinkList *La,LinkList *Lb); void CreatCircularLinkList(LinkList *L,int n); int MonkeyKing(LinkList L,int n); int LinkListLength_Dul(DuLinkList L); int CreateLinkList_Dul(DuLinkList *L,int n); int PrintLinkList_Dul(DuLinkList L); int Locate(DuLinkList *L,ElemType e); 9 //int InterSection(LinkList La,LinkList Lb,LinkList *Lc); void Check_1(); void Check_2(); void Check_3(); …………………………………………………………………………………………………….... main.cpp #include …………………………………………………………………………………………………….... Check_1.cpp #include \#include 10