标签:
//顺序栈 public class OrderStack { //(1)置空栈 void InitStack(SeqStack *S){ S->top = -1; } //(2)判断栈空 int StackEmpty(SeqStack *S){ return S->top == -1; } //(3)判断栈满 int StackFull(SeqStack *S){ return S->top == StackSize-1; } //(4)进栈 void push(S,x){ if(StackFull(S)){ Erro("Stack overflow");//上溢,退出运行 } S->data[++S->top]=x;//栈顶 } //(5)退栈 DataType Pop(S){ if(StackEmpty(S)){ Error("Stack underflow");//下溢,退出运行 } return S->data[S->top--];//栈顶元素出栈后,将栈顶指针下移一位 } //(6)取栈顶元素 DataType StackTop(S){ if(StackEmpty(S)){ Error("Stack underflow");//下溢,退出运行 } return S->data[S->top];// } }
标签:
原文地址:http://blog.csdn.net/howlaa/article/details/42677485