栈的基本操作
’ & '表示引用调用
初始化
InitStack(Stack s);
InitStack(&S);
判空
bool StackEmpty(Stack s); 栈空为true。
StackEmpty(S);
入栈
Push(Stack s, ElemType x); 入栈后,x为栈顶元素
Push(&S,x);
出栈
Pop(Stack s, ElemType x); x返回出栈的栈顶元素。
Pop(&S, &x);
栈顶元素
GetTop(Stack s, ElemType x); 获取栈顶元素,用x返回
GetTop(S, &x);
释放栈
Destory(Stack s);
Destory(&S);
栈空和栈满条件
//顺序栈
//栈空
S.top == -1;
//栈满
S.top == MaxSize - 1;
队列的基本操作
’ & '表示引用调用
初始化队列
InitQueue(Queue q);
InitQueue (&Q);
队列判空
QueueEmpty(Queue q);
QueueEmpty(Q);
入列
EnQueue(Queue q, ElemType x);
EnQueue(&Q, x);
出列
DeQueue(Queue q, ElemType x);
DeQueue(&Q, &x);
队列元素
GetHead(Queue q, ElemType x)
GetHead(Q, &x);
队列满和空的判定条件
//顺序队列
//队列空条件
Q.front == Q.rear == 0;
//链式存储队列
//队空
front == rear
//队满
front == rear -> next;
rear -> next == front;