Description

Our goal here is to build a Stack class and a Queue class that behave pretty much just like your old ones do, but which are implemented with a linked list instead of an array that has to be resized from time to time. But since the fundamental functionality of that linked list involves certain things which might be common to both Stacks and Queues, perhaps we can leverage the tools of inheritance so that we don’t have to duplicate the work of creating a linked list for Stack and then another very similar one for Queue.  So what we’ll do is we’ll create a parent class that will implement the linked list and have public some methods that are common to both Stacks and Queues (like size or toString, etc.), but also some private (well, actually protected) methods that will help with the implementation of the methods that Stack and Queue don’t have in common (like enqueue and push).