Printing stacks P29017


Statement
 

pdf   zip   main.cc

html

Write a procedure

void print_from_top_to_bottom(stack<int>& S);

that prints a line (end line included) with the elements of S from the top to the bottom, separated by spaces.

Also, write a procedure

void print_from_bottom_to_top(stack<int>& S);

that prints a line (end line included) with the elements of S from the bottom to the top, separated by spaces.

Observations

  • The only containers that you can use here are stacks of integer numbers.

  • If you use recursivity in this exercise, you will probably exhaust the recursion stack.

  • The parameters are passed by reference. This avoids copying the stacks during the call, but implies that any changes that you make will modify the original stacks. Take this fact into account when you use these procedures to solve other exercices.

Observation You only need to submit the required procedures; your main program will be ignored.

Information
Author
Salvador Roura
Language
English
Translator
Carlos Molina
Original language
Catalan
Other languages
Catalan
Official solutions
C++
User solutions
C++