Java判断出栈顺序是否正确的方法
public?class?SqStack?{
private?int?size;
private?Object[]?datas;
private?int?top;
public?SqStack(){
this(50);
size?=?50;
}
public?SqStack(int?size)?{
this.size?=?size;
datas?=?new?Object[size];
top?=?-1;
}
public?void?push(Object?data){
//...
}
public?Object?pop(){
//...
}
public?Object?getTop(){
//...
}
public?boolean?isEmpty(){
//...
}
}
public?static?boolean?isStackOutSequence(String?str){
SqStack?s=new?SqStack();
for(int?i=0;i?
for(int?j=i+1;j?
if(str.charAt(j)?
s.push(str.charAt(j));
}
while(!s.isEmpty(){
char?c=(Character)s.pop();
if(!s.isEmpty()&&c>(Character)s.pop())
return?false;
}
}
return?true;
}
?