sequencestack.java
来自「用栈来实现10进制转换8进制的编码」· Java 代码 · 共 70 行
JAVA
70 行
/**
* Created by IntelliJ IDEA.
* User: Administrator
* Date: 2009-2-3
* Time: 14:42:29
* To change this template use File | Settings | File Templates.
*/
public class SequenceStack {
int[] stack;
int top;
int stackSize;
public void initStack(int size) {
stack = new int[size];
stackSize = size;
top = 0;
}
public void destoryStack() {
stack = null;
stackSize = top = 0;
}
public void clearStack() {
top = 0;
}
public boolean stackEmpty() {
return top == 0;
}
public boolean stackFull() {
return top == stackSize;
}
public int stackLength() {
return top;
}
public int getTop() {
if (stackEmpty()) {
return -100000;
}
return stack[top - 1];
}
public boolean push(int val) {
if (stackFull()) {
return false;
}
stack[top++] = val;
return true;
}
public int pop() {
if (stackEmpty()) {
return -100000;
}
return stack[--top];
}
public void stackTraverse(){
for(int i=top;i>0;){
System.out.print(stack[--i]);
}
System.out.println();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?