The issue is you are not setting top
properly, in your constructor you declared a local top
which left stack::top uninitialized.
stack(){
int top=-1; //
}
update to below code, should work:
stack() {
top = -1;
}
1
solved Infix to Postfix conversion – segmentation fault [closed]