/**
* 使用栈存储后缀表达式
* Create by Administrator
* 2018/6/13 0013
* 下午 2:25
**/
public class StackX {
private int maxSize;
private char[] stackArray;
private int top;
public StackX(int size) // 构造函数
{
maxSize = size;
stackArray = new char[maxSize];
top = -1;
}
public void push(char j) // 将项目放在堆栈的顶部
{
stackArray[++top] = j;
}
public char pop() // 从堆栈顶部取项
{
return stackArray[top--];
}
public char peek() // 从堆栈顶部查看
{
return stackArray[top];
}
public boolean isEmpty() // 如果栈为空,则为true
{
return (top == -1);
}
public boolean isFull() // 如果堆栈已满 true
{
return (top == maxSize - 1);
}
public int size() // return size
{
return top + 1;
}
public char peekN(int n) // peek at index n
{
return stackArray[n];
}
public void displayStack(String s) {
System.out.print(s);
System.out.print("Stack (bottom-->top): ");
for (int j = 0; j < size(); j++) {
System.out.print(peekN(j));
System.out.print(' ');
}
System.out.println("");
}
}
/**
* 使用栈存储后缀表达式
* Create by Administrato