#include “function.h”
void Init_stack(SqStack& S) {
S.top = -1;
}
bool Stack_empty(SqStack S) {
if (S.top == -1) {
return true;
}
else {
return false;
}
}
bool Push(SqStack& S, ElemType x) {
if (S.top == 50 - 1) {
return false;
}
S.data[++S.top] = x;
return true;
}
bool GetTop(SqStack S, ElemType& m) {
if (Stack_empty(S)) {
return false;
}
m = S.data[S.top];
return true;
}
bool Pop(SqStack& S, ElemType & x) {
if (Stack_empty(S)) {
return false;
}
x = S.data[S.top–];
return true;
}
void Init_queue(LinkQueue& Q) {
Q.front = Q.rear = (LinkNode*)malloc(sizeof(LinkNode));
Q.front->next = NULL;
}
bool Is_empty(LinkQueue Q) {
if (Q.front == Q.rear) {
return true;
}
else {
return false;
}
}
void EnQueue(LinkQueue& Q, ElemType x) {
LinkNode* s = (LinkNode*)malloc(sizeof(LinkNode));
s->data = x;
s->next = NULL;
Q.rear->next = s;
Q.rear = s;
}
bool DeQueue(LinkQueue& Q, ElemType & x) {
if (Q.front == Q.rear) return false;
LinkNode* p = Q.front->next;
x = p->data;
Q.front->next = p->next;
if (Q.rear == p) Q.rear = Q.front;
free§;
return true;
}



