private Object element[];
private int top;
int maxSize;
private String x,y;
public Stack(int s,String x){
maxSize=s;
element=new Object[maxSize];
top=-1;
this.x=x;
y="";
}
public boolean isEmpty(){
return(top==-1);
}
public void push(Object elt){
top=top+1;
element[top]=elt;
}
public Object pop(){
Object e=element[top];
top=top-1;
return e;
}
public Object peek(){
return element[top];
}
public void change(){
for(int i=0;i<x.length();i++){
push(x.charAt(i));
}
}
public void set(){
while(!isEmpty()){
y=y+pop();
}
System.out.println(y);
}
public boolean eguals(){
return(x.compareTo(y)==0);
}
public static void main(String a[]){
Stack s=new Stack(5,"amma");
s.change();
s.set();
System.out.println("palindrome "+s.eguals());
Stack s2=new Stack(5,"ammaa");
s2.change();
s2.set();
System.out.println("palindrome "+s2.eguals());
}
}
Output
/*C:\Users\KAPILAN\Desktop>java Stack
amma
palindrome true
aamma
palindrome false
C:\Users\KAPILAN\Desktop>*/
No comments:
Post a Comment