Firstly, in C++, a variable length array ( int a[n]; ) is forbidden.
Secondly, on line 24, you call top on an empty stack. This is bad. Do not do this. First check that the stack isn't empty, and only then call top on it.
This doesn't work in c++. The size of an array must be constant at compile time.
You can only do it that way if you allocate memory on the heap for it.
Well i got the mistake in the stack which you mentioned .But there is no problem in the array because i have taken the input of variable n then i have defined the array a.
thanks
It's still illegal in C++. Your compiler is letting you create a variable length array. It shouldn't. It's illegal. It's not C++. It's incorrect C++. Your compiler might let you do it, but it shouldn't. You shouldn't write incorrect code just because the compiler you're happening to use right now happens to let you.