Printing stacks

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.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T10:36:36.346Z

© Jutge.org, 2006–2026.
https://jutge.org
