Environment: Visual Studio, All Windows platforms
It seems that over time, all programmers, engineers and other code authors have come to terms with and fully understand some of the abstract data types that come with the territory of C/C++ coding. Many prefer to use their own abstract data types, while others use some of the existing algorithms provided by the Standard Template Library (STL) or elsewhere. My own list routines evolved over time and I believe this particular set of Doubly Linked List routines should provide most of the full-blown functionality that any coder would ever need.
This source code began its early days in the “C” language before the advent of C++ (yes, this indicates how old I am) and subsequently the STL and its associated Container classes, templates, algorithms, etc. As such, the CLinkedList class is extremely stable, and if you believe that the STL is suitable, please continue to do so by all means. However, if you’re looking for that extra speed that you think could make a difference in your final product, or need a solution on a legacy product, then the CLinkedList class is definitely worthwhile having a look at, because there are virtually no processing overheads when compared to the number of corresponding or appropriate STL function calls.
For those STL users reading this documentation, the obvious and proper use of classes and templates was not in the forefront of my mind when writing the examples, hence the heavy use of type casting the list return data. For this, I offer my apologies to the more discerning user/reader. The intent is to demonstrate functionality rather than style or other programming idioms. Also, if you compile this project, the output is meant to be read.
The source code is fully commented. There is also a set of HTML Help Files included with many examples.
Below is a list of the CLinkedList class member functions, Happy Coding!
Constructor(...) The constructor for the class. int dladd( void* data ) Add ( insert ) a node into the list int dladdins( void* data ) Add a node to the list with an insertion sort. int dlatmark( void ) Test to see if at a previously marked node in the list. void* dlbsearch( void* data ) Perform a binary search of the list. long dlcount( void) Return the number of nodes in the list. int dlclear(void) Deletes all nodes retaining an empty list. int dldelete( void ) Delete the current node. void* dlfind( void* data ) Find a node in the list with this data. void* dlget( void ) Get currency, a "fresh" copy of the data in the current node. void* dlgoback( void ) Travel backwards through the list to the previous node. void* dlgofwd( void ) Travel forwards through the list to the next node. int dlinsert( void* data ) Insert a node into the list at this point. int dlmark( void ) Mark (tag) a particular node in the list. long dlposn( void ) Return the nodes position in the list. int dlqsort( void ) Sort the list using the qsort() library function. int dlreplace( void* data ) Replace the current node with this data. int dlrewind( void ) Rewind to the start of the list. int dlsetcompare( pfunction ) Change the user supplied comparison function to another. int dlsort( void ) Sort the list using a primitive swap sort algorithm. bool dlsorted( void ) Flag indicating whether the list is sorted or not. void* dltofirst( void ) Go to the first node in the list. void* dltolast( void ) Go to the last node in the list. int dltomark( void ) Go to a previously marked node in the list. int dlunmark( void ) Unmark a previously marked node. int DumpMemory( ) Dump the contents of some memory to the debug screen. int dldumplist( void ) Dump the contents of the entire list to the debug screen. int dldumpnode( void ) Dump the contents of a single node to the debug screen. int operator<<( void* ) The same as dladd() void* operator( long ) Array access operator void* operator++( int ) Equates to dlgofwd() void* operator--( int ) Equates to dlgoback()
Updates a 2002 article