What is the output?
#include <iostream>
#include <stack>
using namespace std;
int main()
{
stack<int> s, ss; //declare two stacks
//Check whether s is empty.
cout<<"Empty or not? "<<s.empty()<<endl;
cout<<"The size is "<<s.size()<<endl;
//I randomly push some numbers into s
s.push(100);
s.push(500);
s.push(2);
s.push(13);
cout<<"We push 100, 500, 2, 13 into s. "<<endl;
cout<<"\nThe size is "<<s.size()<<endl<<endl;
//print the elements from top to bottom
cout<<"Print s from top:"<< endl;
while(!s.empty())
{
cout<<s.top()<<" ";
s.pop();
}
cout<<endl<<endl;
//push elements of an array into s
int arr[]={1,5,10};
for(int i=0; i<3;i++)
s.push(arr[i]);
cout<<"Push elements of array, 1, 5, 10 into s."<<endl;
// move elements from s to ss
while(!s.empty())
{
ss.push(s.top());
s.pop();
}
cout<<"Move elements from s to ss. "<<endl;
cout<<"Elements in s are "<<endl;
while(!s.empty())
{
cout<<s.top()<<" ";
s.pop();
}
cout<<endl;
cout<<"Elements in ss are "<<endl;
while(!ss.empty())
{
cout<<ss.top()<<" ";
ss.pop();
}
cout<<endl;
system("pause");
return 0;
}
The output is