public class Stack { public static int CONSTANT_MAX; public int[] data; public int top; public Stack initStack(int max){ Stack stack; if((stack = new Stack()) != null){ stack.top = -1; stack.CONSTANT_MAX = max; stack.data = new int[stack.CONSTANT_MAX]; return stack; } return null; } public boolean isEmptyStack(Stack stack){ boolean b; b = (stack.top == -1); return b; } public boolean isFullStack(Stack stack){ boolean b; b = (stack.top == CONSTANT_MAX); return b; } public void clearStack(Stack stack){ stack.top = -1; } public void setFreeStack(Stack stack){ if(stack != null){ stack = null; } } public int pushStack(Stack stack,int data){ if((stack.top) >= CONSTANT_MAX){ System.out.println("栈溢出!"); return 0; } stack.data[++top] = data; return 1; } public int popStack(Stack stack){ if(stack.top == -1){ System.exit(0); } return (stack.data[stack.top--]); } }
算法_数据结构_栈
最新推荐文章于 2022-11-24 13:55:12 发布