scire
Sadh's C++ Impromptu Routines Ensemble
|
A Singly Linked List class. More...
#include <linkedlist.hpp>
Classes | |
struct | Node |
represent an item node in Singly Linked List More... | |
Public Member Functions | |
SinglyList () | |
initialize a SinglyList object, with head pointing to nullptr More... | |
virtual | ~SinglyList () |
finalize a SinglyList object by deleting all items from the list More... | |
void | Traverse (void(*travfunc)(const Type &)) const |
Traverse each item of the list. More... | |
SzType | Insert (Type item, SzType location=0) |
insert a new item in the list with passed item after location nodes More... | |
bool | RemoveAt (SzType location=0) |
remove the item at location More... | |
bool | Remove (const Type &item) |
remove first item in the linked list that matches passed item. More... | |
virtual SzType | Size () const |
number of elements contained in More... | |
virtual bool | Add (const Type &item) |
add an element More... | |
virtual bool | Deduce () |
deduce one element More... | |
virtual Type | Peek () const |
peek into next element contained in More... | |
virtual bool | IsEmpty () const |
check if empty More... | |
Protected Member Functions | |
const Node * | Head () const |
Protected Attributes | |
Node * | head |
points to first item of the list More... | |
SzType | size |
track count of items in the list More... | |
Friends | |
SzType | GetRidOfDuplicates (SinglyList< Type, SzType > &list) |
iterate through the list and remove duplicate items (i.e. More... | |
const Type & | KthToTheLast (const SinglyList< Type, SzType > &list, SzType k) |
Return the kth to the last item. More... | |
A Singly Linked List class.
Singly linked list contains a linear list of items. Each item points to it's next; the last item of the list points to nullptr. A head pointer points to the first item of the list.
Definition at line 40 of file linkedlist.hpp.
scire::SinglyList< Type, SzType >::SinglyList | ( | ) |
initialize a SinglyList object, with head pointing to nullptr
Definition at line 179 of file linkedlist.hpp.
|
virtual |
finalize a SinglyList object by deleting all items from the list
Definition at line 186 of file linkedlist.hpp.
|
inlinevirtual |
add an element
element | element to be added as new element |
Implements scire::AContainer< Type, SzType >.
Definition at line 80 of file linkedlist.hpp.
|
virtual |
deduce one element
Implements scire::AContainer< Type, SzType >.
Definition at line 313 of file linkedlist.hpp.
|
inlineprotected |
Definition at line 109 of file linkedlist.hpp.
SzType scire::SinglyList< Type, SzType >::Insert | ( | Type | item, |
SzType | location = 0 |
||
) |
insert a new item in the list with passed item after location nodes
item | item to insert as new item in the list |
location | location in the list where the new item to insert |
Definition at line 211 of file linkedlist.hpp.
|
inlinevirtualinherited |
|
virtual |
peek into next element contained in
Implements scire::AContainer< Type, SzType >.
Definition at line 326 of file linkedlist.hpp.
bool scire::SinglyList< Type, SzType >::Remove | ( | const Type & | item | ) |
remove first item in the linked list that matches passed item.
item | item to remove |
Definition at line 281 of file linkedlist.hpp.
bool scire::SinglyList< Type, SzType >::RemoveAt | ( | SzType | location = 0 | ) |
remove the item at location
location | index of item to remove |
Definition at line 246 of file linkedlist.hpp.
|
virtual |
number of elements contained in
Implements scire::AContainer< Type, SzType >.
Definition at line 307 of file linkedlist.hpp.
void scire::SinglyList< Type, SzType >::Traverse | ( | void(*)(const Type &) | travfunc | ) | const |
Traverse each item of the list.
travfunc | function to traverse each item of list with |
Definition at line 199 of file linkedlist.hpp.
|
friend |
iterate through the list and remove duplicate items (i.e.
remove those items that appear more than once)
list | list to operate on |
Definition at line 124 of file linkedlist.hpp.
|
friend |
Return the kth to the last item.
If the list has n items, return (n-k)th item of the list. If k=0, then return last item. If k>=n then it is an error.
list | list ti operate on |
k | k |
Definition at line 156 of file linkedlist.hpp.
|
protected |
points to first item of the list
Definition at line 107 of file linkedlist.hpp.
|
protected |
track count of items in the list
Definition at line 115 of file linkedlist.hpp.