Programming Resources
For Fun and Learning
Charles Cusack
Computer Science
Hope College
main

Python

C++


JAVA
PHP
SQL
Alice

DLListExamples


Description
DLListExamples contains several applications of a doubly-linked lists. The purpose of the example is to show how easy it is to implement a stack or queue given a doubly-linked list

More generally, it demonstrates a general principle: code re-use.

  • dllist.h and dllist.cpp implements a doubly-linked list.
  • queueHasAdllist.h and queueHasAdllist.cpp implements a queue by using a variable of type doubly-linked list and performing operations on that. This is known as a has a relationship because the queue has a dllist in it.
  • stackHasAdllist.h and stackHasAdllist.cpp implements a stack by using a variable of type doubly-linked list and performing operations on that. This is known as a has a relationship because the stack has a dllist in it.
  • queueAsAdllist.h and queueAsAdllist.cpp implements a queue by deriving from the class dllist. This is known as a is a ( or as a) relationship because the stack is a dllist.
  • teststuff.cpp is just a simple program to test the classes. It doesn't do much, but is a simple example of using the classes.
You may notice that the two versions of the stack are virtually identical. You should not take this to indicate that as a and has a relationships are always this way. Usually one is more appropriate than the other. For instance, the as a probably makes more sense in this case.