stack is popped in function still still shows in main function.
Isn't the call should be by reference for the stack given.
void showstack(stack <int> s) {
while (!s.empty()) {
cout << '\t' << s.top();
//stack getting popped
s.pop();
}
}
int main () {
stack <int> s;
s.push(10);
s.push(30);
s.push(5);
s.push(1);
cout << "The stack is : ";
showstack(s);
//The stack should be empty here.
cout << "\ns.size() : " << s.size();//size should not get displayed
//top should be empty
cout << "\ns.top() : " << s.top();
cout << "\ns.pop() : ";
s.pop();
showstack(s);
return 0;
}