CS 201: Data Structures (Winter 2017)

Lab03: Implement a generic linked stack

1. Goals

To practice implementing a linked stack and learn to implement a generic interface.

2. Linked Stack

Today you will implement a stack using links. This is a good chance to practice working with linked structures and to ask questions about the linked list homework.

Before you begin coding

Start implementing LinkedStack.java

3. Array Stack

Once you have your linked stack working, talk with your partner about implementing an array stack (no need to actually implement it). Discuss where newly added items to the stack should go, and how efficient pop and push will be. You should be able to come up with a design that will usually be as efficient as the linked implementation.

4. Recursive Stack

You can think of a stack as having two parts: a top item and a stack containing the rest of the items. Take a look at the RecursiveStack.java demo.

5. Extensions

Note: These are provided as extra practice and challenge. You're not intended to get all the way through them or even necessarily to start them.

This lab modified from one designed by Anna Rafferty.