A Stack made with Linked Lists

A Stack is a last-in-first-out collection of objects.

I have created a class called ListStack which implements a stack using a linked list data structure. The linked list is made up of a set of nodes which are objects of the ListNode class. ListNodes have a value and a reference to the next node in the list. This reference is a variable of type ListNode and it is the "link" in "linked list".

Building a stack class using linked lists requires creating a new nodes everytime a new object is pushed onto the stack as well as updating the links. One nice feature of this scheme compared to the array scheme we've seen before, is that there is no specific limit to the number of items that can be pushed onto the stack. Because each ListNode and the object it refers to (the value field) consume some memory, the only limitation is the amount of memory available to the machine running the program.

StackTest is an application which tests the ListStack class. To perform its tests, it uses a Tester class which tests its two arguments for equality and prints out a message for each test that fails as well as keeping track of the number of failing tests.

Files