#include <orderedList.h>
Though the name says that this is an ordered list, it is not ordered in any fashion until unless the user asks for a particular oredering. The kind of orderings supported currently are the ascending and the descending order sortings by the an algorithm of the users choice. The list is made up of nodes of class TemplateNode. The ordering will be done as per the key value assigned to each node data of the list. This class has to be used with great care as there is enough apportunity to make the code buggy with segmentation faults and memory leaks.
Public Member Functions | |
OrderedList (void) | |
Default constructor. | |
OrderedList (const OrderedList &ol) | |
Copy constructor. | |
virtual | ~OrderedList () |
Destructor. | |
void | push (T *data, double key) |
Pushes a new node on to the list. | |
void | pop (void) |
Pops the last element in the list. | |
int | getSize (void) |
Returns the size of the list. | |
void | sortAscendingBubbleSort (void) |
Sorts the data elements in ascending order based on their key values. | |
void | sortDescendingBubbleSort (void) |
Sorts the data elements in descending order based on their key values. | |
tutk::TemplateNode< T > * | getFirstNodePtr (void) |
Returns a pointer to the first node of the list. |
|
Default constructor. Initialises a zero length list. |
|
Copy constructor. New copy of the data is not created but the data is only shared. i.e after OrederedList A(B), changes to data of B get reflected in the data of A. But the user should keep in mind that passing an empty object to a function would result in a call by value, where as passing a non-empty object would result in call by reference. The user should also keep in mind that empty objects will not be copied by reference. i.e. copy construction using an empty object followed by data creation would lead to objects have different data-space in memory.
After the above code snippet is executed, size of l1 is 1, where as size of l2 is still 0. |
|
Returns a pointer to the first node of the list. Will return NULL is the list is empty. |
|
Returns the size of the list. i.e returns the number of nodes added to the list. |
|
Pops the last element in the list.
The last data item is destroyed after a call to this function. |
|
Pushes a new node on to the list. The user has to first create a new data item and then pass a pointer to this data item as the parameter to this function. The user should not bother to delete that data item as this List, on to which the node has been pushed, will delete it. The key is the value which shall be used to order the list. NOTE: The data item should be created using new and not malloc. |
|
Sorts the data elements in ascending order based on their key values. The sorting is done using the bubble-sort algorithm. |
|
Sorts the data elements in descending order based on their key values. The sorting is done using the bubble-sort algorithm. |