< Back

Lecture 28 - Linked Lists


As usual, create a directory to hold today's activities:

  $ mkdir ~/cs170/labs/lab28 
  $ cd ~/cs170/labs/lab28 

Abstract Data Types


Lab Activity 1
Stack

A Stack is what we refer to as a "Last In, First Out" (LIFO) data structure. The data in a stack is placed an retrieved like a stack of plates at the commons: You can only interact with the top plate of the stack. The same can be said for the stack data structure: You can only interact with the most recently placed piece of data in the stack.

Details

Create a class ListStack which inherits the Stack interface defined below. Your class should use the LinkedList class to represent the stack.

Stack.h

Make sure you test your methods carefully. Think about what the edge cases are, and how to handle them appropriately.

Test Program


Lab Activity 2

A Queue is what we refer to as a "First in, First out" (FIFO) data structure. It behaves just like the line at the cavern. The person who entered the queue first will be served first, etc. In our data structure, that means the data that has been in the queue the longest will be processed next. This does not mean that we will keep track of that time. We will simply store elements in such a way that it gets processed correctly.

Details

Create a class ListQueue which inherits the Queue interface defined below. Your class should use the LinkedList class to represent the stack.

Queue.h

Make sure you test your methods carefully. Think about what the edge cases are, and how to handle them appropriately.

Test Program