pop()
is not working because you are using different objects for push and pop.
You don’t need to define another class for push and pop, they are operation add those function inside Stack class.
class Stack {
... // members and constructor
public void push(){..}
public void pop(){..}
public void show(){..}
}
And create an object of Stack class and use for push, pop and show
Stack s = new Stack(n);
while(true){
...
switch(choice){
case 1:
s.push();
break;
case 2:
s.pop();
break;
case 3:
s.show();
break;
default:
System.out.println("Invalid Option");
break;
}
}
3
solved Stack implementation java