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 object with an associated header object to manage it. And, a double linked list object 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, gives back a linkListObj with a 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. Gives back 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 can't see the list above me that 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.

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);
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.

Clone this wiki locally