Skip to content
Jim Lee edited this page Mar 19, 2020 · 31 revisions

Abstract:

Dynamic lists of things that grow and shrink as necessary. The fundamental base of so much in computing are lists of some sort.

In this library we have two different types of lists. A linked list class with an associated header class to manage it. And, a double linked list class that can pretty much self manage. Along with these are stack and queue classes built from these primary classes for you to use.

linkListObj:

Constructor:

linkListObj(void);
No parameters, creates a linkListObj with its "next" pointer set to NULL. When in a list, this pointer contains the address of the next node in the list.

Other methods:

void linkAfter(linkListObj* present);
Given a pointer to a link list object, link yourself into a list after this object.

void linkToEnd(linkListObj* present);
Given any link in a list of link list objects, walk the list to the end. Then, link yourself into the list after the last link list object of this list.

linkListObj* getNext(void);
Return the value of your link list "next" pointer.

void setNext(linkListObj* ptr);
Set the value of your link list "next" pointer.

void deleteTail(void);
Call delete on every link list object that is linked to the current link list object's "next" list pointer. Effectively deleting everything beyond yourself on the list. But not yourself.

bool isGreaterThan(linkListObj* compObj);
This method is intended to be inherited and filled in by the user. It needs to be able to return if the current link list object should be considered greater than the passed in link list object.

bool isLessThan(linkListObj* compObj);
This method is intended to be inherited and filled in by the user. It needs to be able to return if the current link list object should be considered less than the passed in link list object.

linkList:

Constructor:

linkList(void);
No parameters. Creates a link list manager object. Remember, link lists can't really manage themselves. Why? Because they only can "see" what they are linked to, by their "next" pointers. They have no way to know what is linked to them by other link list object's "next" pointers. In other words; I can see the list below me that I"m pointing at. I have no way of "seeing" what is pointing at me.

Other methods:

void addToTop(linkListObj* newObj);
Given a pointer to a link list object, link it into the top of the list.

void addToEnd(linkListObj* newObj);
Given a pointer to a link list object, link it into the end (bottom) of the list.

void unlinkTop(void);
This will unlink the top link list object from the list. It does NOT delete this object. So you had better have already have saved off a copy of its address or this will just leak memory.

void unlinkObj(linkListObj* oldObj);
This will search a list for a lik list Object that's address matches the address passed in. Once it is found, it will unlink this object from the list. Just like unlinkTop() above, it does NOT delete the object. Its up to the caller to keep track of the object and delete it if necessary. link void dumpList(void);
This will call delete, freeing the memory, on every link list object in the list. It does NOT delete the list manager itself.

bool isEmpty(void);
Returns whether there is any link list object on the list. Returns true if the list is empty.

linkListObj* getFirst(void);
Returns the address of the fist link list object on the list. NULL if there is none.

linkListObj* getLast(void);
Returns the address of the last link list object on the list. NULL if there is none.

linkListObj* findMax(linkListObj* present);
Using the user written isGreaterThan() and/or isLessThan() link list object's methods, returns the greatest link list object on the list. NULL if the list is empty.

linkListObj* findMin(linkListObj* present);
Using the user written isGreaterThan() and/or isLessThan() link list object's methods, returns the smallest link list object on the list. NULL if the list is empty.

void sort(bool decending); //NOTE This needs to be changed to descending
Using the user written isGreaterThan() and/or isLessThan() link list object's methods, this will sort the list. If the passed in bool decending is true, the list will be sorted in descending order. Else it will be sorted in aescending order.

int getCount(void);
Passes back the number of link list object on the list.

linkListObj* getByIndex(int index);
Passes back the link list object corresponding to the passed in index. Link lists are indexs like arrays starting at 0. Passes back a NULL if the link list object is not present.

dblLinkListObj:

Constructor:

dblLinkListObj(void);
No parameters. Creates a double link list object. Both "next" and "previous" pointers are set to NULL. When in a list, these pointers contains the address of the next and previous nodes in our list.

Other methods:

void linkAfter(dblLinkListObj* present);
Given a pointer to a double link list object, link yourself after it. This works correctly at both the middle and tail end of a double linked list. NULL pointers are ignored.

void linkBefore(dblLinkListObj* present);
Given a pointer to a double link list object, link yourself before it. This works correctly at both the middle and tail end of a double linked list. NULL pointers are ignored.

dblLinkListObj* getFirst(void);

This, starting at the current double link list object, traverses up the "previous" links to find and returns a pointer to the first object on the list. This could possibly be the current node itself.

dblLinkListObj* getLast(void);
This, starting at the current double link list object, traverses down the "next" links to find and returns a pointer to the last object on the list. Again, this could possibly be the current node itself.

void linkToEnd(dblLinkListObj* present);
Given a pointer to any node in a list, this will link the current object after the last node in that list.

void linkToStart(dblLinkListObj* present);
Given a pointer to any node in a list, this will link the current object before the first node in that list.

dblLinkListObj* getTailObj(int index);
Hand back a pointer to the "nth" node of the current object's tail. Like an array starting count at the current object as zero.

void unhook(void);
This will unhook the current node from a list, if it is in one.

void dumpTail(void);
Delete all nodes on the list pointed to by the current "next" pointer. In other words, deletes the entire tail leaving the current node as the tail of the remaining list.

void dumpHead(void);
Delete all nodes on the list pointed to by the current "pervious" pointer. In other words, deletes the entire head section of the list leaving the current node as the head of the remaining list.

void dumpList(void);
Deletes everything in the list with the exception of the current node.

int countTail(void);
Counts and returns the number of nodes in the list pointed to by our "next" pointer.

int countHead(void);
Counts and returns the number of nodes in the list pointed to by our "previous" pointer.

stack:

FIRST in LAST out list of objects.

Constructor:

stack(void);
No parameters. Returns a stack object.

Other methods:

void push(linkListObj* newObj);
"Pushes" a linkListObj object onto the current stack object.

linkListObj* pop(void);
Pops a linkListObj off of the current stack object, then returns a pointer to that object. A NULL is returned if there is no object to pop off the stack.

linkListObj* peek(void);
Returns a pointer to the object on the top of the stack without unlinking it. Allowing you to have a look without actually changing anything.

queue:

FIRST in FIRST out list of objects.

Constructor:

queue(void);
No parameters. Returns a queue object.

Other methods:

void push(linkListObj* newObj);
"Pushes" a linkListObj object onto the current queue object.

linkListObj* pop(void);
Pops a linkListObj off of the current queue object, then returns a pointer to that object. A NULL is returned if there is no object to pop off the queue.

linkListObj* peek(void);
Returns a pointer to the object on the top of the queue without unlinking it. Allowing you to have a look without actually changing anything.