所以我很困惑,需要一个建议.在Java中,我可以实现自己的Stack,或者我可以使用java.util提供的Stack.
手册:
public class stack {
private int maxSize; //max size of stack
private char[] stackArray;
private int top; //index poistion of last element
public stack(int size){
this.maxSize=size;
this.stackArray=new char[maxSize];
this.top=-1; //
}
public void push(char j){
if (isFull()) {
System.out.println("SORRY I CANT PUSH MORE");
}else{
top++;
stackArray[top]=j;
}
}
public char pop(){
if(isEmpty()){
System.out.println("Sorry I cant pop more!");
return '0';
}else{
int oldTop=top;
top--;
return stackArray[oldTop];
}
}
public char peek(){
if(!isEmpty()) {
return stackArray[top];
}
}
public boolean …Run Code Online (Sandbox Code Playgroud)