Rudiments
|
Public Member Functions | |
singlylinkedlist () | |
~singlylinkedlist () | |
void | prepend (valuetype value) |
void | prepend (singlylinkedlistnode< valuetype > *node) |
void | append (valuetype value) |
void | append (singlylinkedlistnode< valuetype > *node) |
void | insertAfter (singlylinkedlistnode< valuetype > *node, valuetype value) |
void | insertAfter (singlylinkedlistnode< valuetype > *node, singlylinkedlistnode< valuetype > *newnode) |
void | moveAfter (singlylinkedlistnode< valuetype > *node, singlylinkedlistnode< valuetype > *nodetomove) |
void | detach (singlylinkedlistnode< valuetype > *node) |
bool | remove (valuetype value) |
bool | removeAndDelete (valuetype value) |
bool | removeAndArrayDelete (valuetype value) |
bool | removeAll (valuetype value) |
bool | removeAllAndDelete (valuetype value) |
bool | removeAllAndArrayDelete (valuetype value) |
bool | remove (singlylinkedlistnode< valuetype > *node) |
bool | removeAndDelete (singlylinkedlistnode< valuetype > *node) |
bool | removeAndArrayDelete (singlylinkedlistnode< valuetype > *node) |
uint64_t | getLength () const |
singlylinkedlistnode< valuetype > * | getFirst () |
singlylinkedlistnode< valuetype > * | getLast () |
singlylinkedlistnode< valuetype > * | getNext (singlylinkedlistnode< valuetype > *node) |
singlylinkedlistnode< valuetype > * | find (valuetype value) |
singlylinkedlistnode< valuetype > * | find (singlylinkedlistnode< valuetype > *startnode, valuetype value) |
void | insertionSort () |
void | heapSort () |
void | clear () |
void | clearAndDelete () |
void | clearAndArrayDelete () |
void | print () const |
void | print (uint64_t count) const |
The singlylinkedlist class allows you to store an arbitrary number of values in a singly-linked list. Since the singlylinkedlist class is template-based, you can store arbitrary types of values.
Each singlylinkedlist is composed of a series of singlylinkedlistnodes. Each singlylinkedlistnode contains a value.
This class is similar to the linkedlist class but uses less memory and many of its operations are faster.
However, the move, detach and remove operations are much slower. If your application must run these operations regularly, you should consider using the linkedlist class instead.
singlylinkedlist< valuetype >::singlylinkedlist | ( | ) |
Creates an empty instance of the singlylinkedlist class.
singlylinkedlist< valuetype >::~singlylinkedlist | ( | ) |
Deletes this instance of the singlylinkedlist class and all of its singlylinkedlistnodes. Note however, that the value stored in each singlylinkedlistnode is not deleted by this call.
void singlylinkedlist< valuetype >::append | ( | singlylinkedlistnode< valuetype > * | node | ) |
Appends already created singlylinkedlistnode "node" to the singlylinkedlist.
void singlylinkedlist< valuetype >::append | ( | valuetype | value | ) |
Creates a new singlylinkedlistnode containing "value" and appends it to the singlylinkedlist.
void singlylinkedlist< valuetype >::clear | ( | ) |
Deletes all singlylinkedlistnodes currently in the singlylinkedlist. Note however, that the value stored in each singlylinkedlistnode is not deleted by this call.
void singlylinkedlist< valuetype >::clearAndArrayDelete | ( | ) |
Deletes all singlylinkedlistnodes currently in the singlylinkedlist, deleting the value stored in each singlylinkedlistnode as well, which is presumed to be an array.
void singlylinkedlist< valuetype >::clearAndDelete | ( | ) |
Deletes all singlylinkedlistnodes currently in the singlylinkedlist, deleting the value stored in each singlylinkedlistnode as well.
void singlylinkedlist< valuetype >::detach | ( | singlylinkedlistnode< valuetype > * | node | ) |
Detaches "node" from the list.
Note that this operation requires a search and is expensive in both execution time and code size. Consider using the linkedlist class.
singlylinkedlistnode<valuetype>* singlylinkedlist< valuetype >::find | ( | singlylinkedlistnode< valuetype > * | startnode, |
valuetype | value | ||
) |
Returns a pointer to the first singlylinkedlistnode after "startnode" containing "value" or NULL if "value" was not found.
singlylinkedlistnode<valuetype>* singlylinkedlist< valuetype >::find | ( | valuetype | value | ) |
Returns a pointer to the first singlylinkedlistnode containing "value" or NULL if "value" was not found.
singlylinkedlistnode<valuetype>* singlylinkedlist< valuetype >::getFirst | ( | ) |
Returns the first node in the singlylinkedlist.
singlylinkedlistnode<valuetype>* singlylinkedlist< valuetype >::getLast | ( | ) |
Returns the last node in the singlylinkedlist.
uint64_t singlylinkedlist< valuetype >::getLength | ( | ) | const |
Returns the number of nodes in the singlylinkedlist.
singlylinkedlistnode<valuetype>* singlylinkedlist< valuetype >::getNext | ( | singlylinkedlistnode< valuetype > * | node | ) |
Returns the node after "node" or NULL if this node is the last node in the list. "node" is presumed to be in the list.
void singlylinkedlist< valuetype >::heapSort | ( | ) |
Sorts the singlylinkedlist in ascending order using a heap sort algorithm. This sort is faster than heapSort() but uses additional memory in proportion to the size of the list.
void singlylinkedlist< valuetype >::insertAfter | ( | singlylinkedlistnode< valuetype > * | node, |
singlylinkedlistnode< valuetype > * | newnode | ||
) |
Inserts already created singlylinkedlistnode "node" into the singlylinkedlist after "node".
void singlylinkedlist< valuetype >::insertAfter | ( | singlylinkedlistnode< valuetype > * | node, |
valuetype | value | ||
) |
Creates a new singlylinkedlistnode containing "value" and inserts it into the singlylinkedlist after "node".
void singlylinkedlist< valuetype >::insertionSort | ( | ) |
Sorts the singlylinkedlist in ascending order using a modified insertion sort algorithm. This sort is slower than heapSort() but uses no additional memory.
void singlylinkedlist< valuetype >::moveAfter | ( | singlylinkedlistnode< valuetype > * | node, |
singlylinkedlistnode< valuetype > * | nodetomove | ||
) |
Moves node "nodetomove" to the position after "node" in the singlylinkedlist.
Note that this operation requires a search and is expensive in both execution time and code size. Consider using the linkedlist class.
void singlylinkedlist< valuetype >::prepend | ( | singlylinkedlistnode< valuetype > * | node | ) |
Prepends already created singlylinkedlistnode "node" to the singlylinkedlist.
void singlylinkedlist< valuetype >::prepend | ( | valuetype | value | ) |
Creates a new singlylinkedlistnode containing "value" and prepends it to the singlylinkedlist.
void singlylinkedlist< valuetype >::print | ( | ) | const |
Prints out a representation of the linkedlist.
void singlylinkedlist< valuetype >::print | ( | uint64_t | count | ) | const |
Prints out a representation of the first "count" nodes of the linkedlist.
bool singlylinkedlist< valuetype >::remove | ( | singlylinkedlistnode< valuetype > * | node | ) |
Removed singlylinkedlistnode "node" from the singlylinkedlist.
Note that this operation requires a search and is expensive in both execution time and code size. Consider using the linkedlist class.
Returns true on success and false on failure.
bool singlylinkedlist< valuetype >::remove | ( | valuetype | value | ) |
Deletes the first singlylinkedlistnode containing "value".
Note that this operation requires a search and is expensive in both execution time and code size. Consider using the linkedlist class.
Returns true on success and false on failure.
bool singlylinkedlist< valuetype >::removeAll | ( | valuetype | value | ) |
Deletes all singlylinkedlistnodes containing "value".
Note that this operation requires a search and is expensive in both execution time and code size. Consider using the linkedlist class.
Returns true on success and false on failure.
bool singlylinkedlist< valuetype >::removeAllAndArrayDelete | ( | valuetype | value | ) |
Deletes all singlylinkedlistnodes containing "value", deleting the values stored in the singlylinkedlistnodes as well, which are presumed to be arrays.
Note that this operation requires a search and is expensive in both execution time and code size.
Returns true on success and false on failure.
bool singlylinkedlist< valuetype >::removeAllAndDelete | ( | valuetype | value | ) |
Deletes all linkedlistnodes containing "value", deleting the values stored in the linkedlistnodes as well.
Note that this operation requires a search and is expensive in both execution time and code size.
Returns true on success and false on failure.
bool singlylinkedlist< valuetype >::removeAndArrayDelete | ( | singlylinkedlistnode< valuetype > * | node | ) |
Removed singlylinkedlistnode "node" from the singlylinkedlist, deleting the value stored in the singlylinkedlistnode as well, which is presumed to be an array.
Note that this operation does not require a search and is far less expensive than the remove(value) operation and removeAll().
Returns true on success and false on failure.
bool singlylinkedlist< valuetype >::removeAndArrayDelete | ( | valuetype | value | ) |
Deletes the first singlylinkedlistnode containing "value", deleting the value stored in the singlylinkedlistnode as well, which is presumed to be an array.
Note that this operation requires a search and is expensive in both execution time and code size.
Returns true on success and false on failure.
bool singlylinkedlist< valuetype >::removeAndDelete | ( | singlylinkedlistnode< valuetype > * | node | ) |
Removed singlylinkedlistnode "node" from the singlylinkedlist, deleting the value stored in the singlylinkedlistnode as well.
Note that this operation does not require a search and is far less expensive than the remove(value) operation and removeAll().
Returns true on success and false on failure.
bool singlylinkedlist< valuetype >::removeAndDelete | ( | valuetype | value | ) |
Deletes the first singlylinkedlistnode containing "value", deleting the value stored in the singlylinkedlistnode as well.
Note that this operation requires a search and is expensive in both execution time and code size.
Returns true on success and false on failure.