public class ArrayStack {
private int mayStack;
private int[] stack;
private int top=-1;
public ArrayStack(int mayStack){
this.mayStack=mayStack;
stack= new int[mayStack];
}
public boolean Empty(){
return this.top==-1;
}
public boolean Full(){
return this.top==this.mayStack-1;
}
public void Push(int value){
if(Full()){
throw new RuntimeException("栈已经满了");
}
top++;
stack[top]=value;
}
public int Pop(){
if(Empty()){
throw new RuntimeException("此栈已空");
}
int value = stack[top];
top--;
return value;
}
public void Search(){
if(Empty()){
throw new RuntimeException("此栈已空");
}
for(int i=0;i<stack.length;i++){
System.out.print("stack["+i+"]="+stack[i]+"\t");
}
}
public int Length(){
return this.top+1;
}
}
public class Test {
public static void main(String[] args) {
boolean test=huiwen("hahhaha");
System.out.println(test);
}
private static boolean huiwen(String str) {
ArrayStack arrayStack= new ArrayStack(10);
if(!arrayStack.Full()){
for(int i=0;i<str.length();i++){
arrayStack.Push(str.charAt(i));
}
}
String string="";
int length = arrayStack.Length();
for(int j=0;j<length;j++){
char pop = (char)arrayStack.Pop();
string+=pop;
}
if(str.equals(string)){
return true;
}else {
return false;
}
}
}