Error in Stacks program

I am getting a run-time error in my program.
Here is the code:


[1]


  [1]: http://pastebin.com/Pgd2jbfm

The program shows unknown values when you select the 3rd option. Please help.
Thanks in advance.

You have not initialized next pointer of the last element in the stack to NULL. Just write a constructor in the st class:
st() {
next = NULL;
}
That would solve your problem.

Also you are not releasing the memory allocated by new in option 2, causing memory leaks. In case 2, before the break statement, write this statement: delete ptr;

If you want an implementation of a stack, you should consider using std::stack class in STL. Here’s a reference to STL stack: http://www.cplusplus.com/reference/stack/stack/

Thanks a lot.

//