scire
Sadh's C++ Impromptu Routines Ensemble
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
scire::SinglyList< Type, SzType > Class Template Reference

A Singly Linked List class. More...

#include <linkedlist.hpp>

Inheritance diagram for scire::SinglyList< Type, SzType >:
scire::AContainer< Type, SzType >

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 NodeHead () const
 

Protected Attributes

Nodehead
 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...
 

Detailed Description

template<typename Type, typename SzType = int>
class scire::SinglyList< Type, SzType >

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.

Constructor & Destructor Documentation

template<typename Type , typename SzType >
scire::SinglyList< Type, SzType >::SinglyList ( )

initialize a SinglyList object, with head pointing to nullptr

Definition at line 179 of file linkedlist.hpp.

template<typename Type , typename SzType >
scire::SinglyList< Type, SzType >::~SinglyList ( )
virtual

finalize a SinglyList object by deleting all items from the list

Definition at line 186 of file linkedlist.hpp.

Member Function Documentation

template<typename Type , typename SzType = int>
virtual bool scire::SinglyList< Type, SzType >::Add ( const Type &  element)
inlinevirtual

add an element

Parameters
elementelement to be added as new element
Returns
true on success

Implements scire::AContainer< Type, SzType >.

Definition at line 80 of file linkedlist.hpp.

template<typename Type , typename SzType >
bool scire::SinglyList< Type, SzType >::Deduce ( )
virtual

deduce one element

Returns
true on success

Implements scire::AContainer< Type, SzType >.

Definition at line 313 of file linkedlist.hpp.

template<typename Type , typename SzType = int>
const Node* scire::SinglyList< Type, SzType >::Head ( ) const
inlineprotected

Definition at line 109 of file linkedlist.hpp.

template<typename Type , typename SzType >
SzType scire::SinglyList< Type, SzType >::Insert ( Type  item,
SzType  location = 0 
)

insert a new item in the list with passed item after location nodes

Parameters
itemitem to insert as new item in the list
locationlocation in the list where the new item to insert
Returns
SzType location where item inserted

Definition at line 211 of file linkedlist.hpp.

template<typename Type , typename SzType = int>
virtual bool scire::AContainer< Type, SzType >::IsEmpty ( ) const
inlinevirtualinherited

check if empty

Returns
true when empty

Definition at line 75 of file container.hpp.

template<typename Type , typename SzType >
Type scire::SinglyList< Type, SzType >::Peek ( ) const
virtual

peek into next element contained in

Returns
element

Implements scire::AContainer< Type, SzType >.

Definition at line 326 of file linkedlist.hpp.

template<typename Type , typename SzType >
bool scire::SinglyList< Type, SzType >::Remove ( const Type &  item)

remove first item in the linked list that matches passed item.

Returns
true if found and removed
Parameters
itemitem to remove

Definition at line 281 of file linkedlist.hpp.

template<typename Type , typename SzType >
bool scire::SinglyList< Type, SzType >::RemoveAt ( SzType  location = 0)

remove the item at location

Returns
true on success
Parameters
locationindex of item to remove

Definition at line 246 of file linkedlist.hpp.

template<typename Type , typename SzType >
SzType scire::SinglyList< Type, SzType >::Size ( ) const
virtual

number of elements contained in

Returns
current size

Implements scire::AContainer< Type, SzType >.

Definition at line 307 of file linkedlist.hpp.

template<typename Type , typename SzType >
void scire::SinglyList< Type, SzType >::Traverse ( void(*)(const Type &)  travfunc) const

Traverse each item of the list.

Parameters
travfuncfunction to traverse each item of list with

Definition at line 199 of file linkedlist.hpp.

Friends And Related Function Documentation

template<typename Type , typename SzType = int>
SzType GetRidOfDuplicates ( SinglyList< Type, SzType > &  list)
friend

iterate through the list and remove duplicate items (i.e.

remove those items that appear more than once)

Returns
number of duplicates detected in original list
Parameters
listlist to operate on

Definition at line 124 of file linkedlist.hpp.

template<typename Type , typename SzType = int>
const Type& KthToTheLast ( const SinglyList< Type, SzType > &  list,
SzType  k 
)
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.

Returns
const ref to (n-k)the item
Parameters
listlist ti operate on
kk

Definition at line 156 of file linkedlist.hpp.

Member Data Documentation

template<typename Type , typename SzType = int>
Node* scire::SinglyList< Type, SzType >::head
protected

points to first item of the list

Definition at line 107 of file linkedlist.hpp.

template<typename Type , typename SzType = int>
SzType scire::SinglyList< Type, SzType >::size
protected

track count of items in the list

Definition at line 115 of file linkedlist.hpp.


The documentation for this class was generated from the following file: