Stacks Exercises

  1. List the basic operations of a stack (and explain each one to the members at your table)
  2. Identify the Big-O for each of the basic operations
  3. Identify multiple examples of stacks in everyday life
  4. Compare and contrast lists and stacks (for example, which methods need to be changed?)
  5. Write the contents of an array stack after each of the following operations (be sure to clearly indicate the top element in the stack):
    • push( A )
    • push( B )
    • pop( )
    • push( C )
    • pop( )
    • pop( )
    Repeat with a linked stack.
  6. Write the contents of an array stack after each of the following operations (be sure to clearly indicate the top element in the stack):
    • push( 's' )
    • push( 't' )
    • push( 'r' )
    • push( 'e' )
    • push( 's' )
    • push( 's' )
    • push( 'e' )
    • push( 'd' )
    • pop( )
    • pop( )
    • pop( )
    • pop( )
    • pop( )
    • pop( )
    • pop( )
    • pop( )
    Repeat with a linked stack.
    What word is formed from the collective calls to pop?
  7. Linked stack demo: Pushes p, o, o, and l onto a stack and then pops each one of them off (with adapted code from the textbook).

Last Modified: