Question: Suppose stack stk1 contains (from top to bottom) the values 6, 4, 5, and suppose stack stk2 contains (from top to bottom) the values 2,
Suppose stack stk1 contains (from top to bottom) the values 6, 4, 5, and suppose stack stk2 contains (from top to bottom) the values 2, 1, 3. What will be the output of the following code ?
while ( stk1.top( ) != 5 ) {
stk2.push( stk1.top( ) );
stk1.pop( );
}
while ( ! stk2.empty( ) ) {
stk1.push( stk2.top( ) );
stk2.pop( );
}
while( ! stk1.empty( ) ) {
cout << stk1.top( ) << " ";
stk1.pop( );
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
