Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members

tutk::OrderedList< T > Class Template Reference

#include <orderedList.h>

List of all members.


Detailed Description

template<class T>
class tutk::OrderedList< T >

A class which implements a doubly linked list which can be ordered.

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.


Constructor & Destructor Documentation

template<class T>
tutk::OrderedList< T >::OrderedList void   ) 
 

Default constructor.

Initialises a zero length list.

template<class T>
tutk::OrderedList< T >::OrderedList const OrderedList< T > &  ol  ) 
 

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.

OrderedList< T > l1;
OrderedList< T > l2(l1);
l1.push(&T, key);

After the above code snippet is executed, size of l1 is 1, where as size of l2 is still 0.


Member Function Documentation

template<class T>
tutk::TemplateNode< T > * tutk::OrderedList< T >::getFirstNodePtr void   ) 
 

Returns a pointer to the first node of the list.

Will return NULL is the list is empty.

template<class T>
int tutk::OrderedList< T >::getSize void   ) 
 

Returns the size of the list.

i.e returns the number of nodes added to the list.

template<class T>
void tutk::OrderedList< T >::pop void   ) 
 

Pops the last element in the list.

The last data item is destroyed after a call to this function.
In case of an object with multiple references is pop-ed out to empty-ness, then the multiple references would no longer hold. Each individual object would have its own data in memory on subsequent refilling of the object.

template<class T>
void tutk::OrderedList< T >::push T *  data,
double  key
 

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.

template<class T>
void tutk::OrderedList< T >::sortAscendingBubbleSort void   ) 
 

Sorts the data elements in ascending order based on their key values.

The sorting is done using the bubble-sort algorithm.

template<class T>
void tutk::OrderedList< T >::sortDescendingBubbleSort void   ) 
 

Sorts the data elements in descending order based on their key values.

The sorting is done using the bubble-sort algorithm.


The documentation for this class was generated from the following file:
Generated on Mon Nov 22 11:12:42 2004 for ImprolaLib by doxygen 1.3.7