package AnagramOfString;
import java.util.Stack;
public class mainClass{
public static void insertAtBottom(Stack stack,int data1)
{
if(stack.isEmpty())
{
stack.push(data1);
return;
}
int data=(int)stack.pop();
insertAtBottom(stack,data1);
stack.push(data);
return;
}
public static void reverse(Stack<Integer> main,Stack<Integer> helper,int index)
{
if(main.isEmpty())
{
return;
}
Integer data=main.pop();
reverse(main,helper,index++);
helper.push(data);
if(index==0)
{
while(!helper.isEmpty())
{
main.push(helper.pop());
}
}
return;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Stack<Integer> stack=new Stack<>();
stack.push(1);
stack.push(2);
stack.push(3);
stack.push(4);
System.out.println(stack);
Stack<Integer> stack1=new Stack<>();
reverse(stack,stack1,0);
System.out.println(stack);
}
}