My program for reversing a stack is not working pls look into the matter
public class Reversestack {
public static void main(String[] args) throws Exception {
stackoperations stack=new stackoperations(5);
for(int i=1;i<=5;i++) {
stack.push(i*10);}
stack.display();
stackoperations helper=new stackoperations(5);
reverseStack(stack,helper,0);
stack.display();
}
public static void reverseStack(stackoperations stack,stackoperations helper,int index) throws Exception {
if(stack.isEmpty()) {
return;
}
int item=stack.pop();
reverseStack(stack,helper,index+1);
helper.push(item);
if(index==0) {
while(!helper.isEmpty()) {
stack.push(helper.pop());
}
}
}
}