in the code below i am unable to pop the value from “helper stack” and push into “mystack” and im very confident about push and pop functions and have checked them multiple times (the’re fine )
public class reverse_mystack {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
stack_using_arrays mystack = new stack_using_arrays();
stack_using_arrays helper = new stack_using_arrays();
for (int i = 10; i < 60; i = i + 10) {
mystack.push(i);
}
// System.out.print(“mystack=>”);
mystack.display();
reverse_Stack(mystack, helper, 0);
mystack.display();
}
public static void reverse_Stack(stack_using_arrays mystack, stack_using_arrays helper, int index)
throws Exception {
if (mystack.isEmpty())
return;
int item = mystack.pop();
reverse_Stack(mystack, helper, index + 1);
helper.push(item);
if(index==0) {
helper.display();
for(int i=0;i<5;i++) {
int val=helper.pop();
mystack.push(val);
}
}
}
}