Lecture 25 -- April 19, 2007
You need to get your major applications in or you will not be able to take your upper division CS classes although you will be able to register for them. You will be individually dropped from those classes unless you are an official CS major or minor.
We talked about stacks
as a last in first out (LIFO) data structure
as a data structure with two required operations: push and pop
with additional operations: isFull, isEmpty, peek
contiguous implementations : arrays of Objects
generic Vectors
type safe Vectors
linked implementations using Node as an external public class
using Node as an internal private class
We demonstrated that you can not remove the item at the bottom of the stack without removing the elements above it first.
We saw that the same test program worked identically regardless of the implementation of the Stack.
Each of the classes is named Stack in the code and must be renamed as such to be run with TestStack
ArrayStack.java - uses a generic array of Objects -
because it's an array, its size must be fixed at creation time
it currently has a default constructor with size 100
it could be augmented with an explicit value constructor if a different size were desired
GenericVectorStack.java - not type safe
TypeSafeStack.java - uses a Vector of Integers
LinkedListStack.java - has Node defined as an inner class
TestStack.java - puts 25 Integer elements on the stack, pops them off and prints them , then tries to pop a 26th element off the stack and print it.
TestStack2.java - puts a variety of 8 Objects on the stack and then pops them off and prints them
Each of these classes is named Queue in the code
ArrayQueue.java
LinkedQueue.java
We talked about queues
as a first in first out (FIFO) data structure