Data Structures & Algorithms in C++
Goodrich, Tamassia, Mount and Goldwasser
Loading...
Searching...
No Matches
Data Structures | Public Member Functions | Friends
dsac::list::SinglyLinkedList< T > Class Template Reference

singly linked list, akin to std::forward_list More...

#include <singly_linked.h>

Collaboration diagram for dsac::list::SinglyLinkedList< T >:
Collaboration graph

Data Structures

class  const_iterator
 
class  iterator
 

Public Member Functions

 SinglyLinkedList ()
 Constructs an empty list.
 
int size () const
 
bool empty () const
 
T & front ()
 
const T & front () const
 
T & back ()
 
const T & back () const
 
void push_front (const T &elem)
 
void pop_front ()
 Removes the first element of the list; behavior undefined if list is empty.
 
void push_back (const T &elem)
 
iterator begin ()
 Returns iterator for the front of the list.
 
const_iterator begin () const
 Returns const_iterator for the front of the list.
 
iterator end ()
 Returns iterator for the end of the list.
 
const_iterator end () const
 Returns const_iterator for the end of the list.
 
iterator insert_after (iterator it, const T &elem)
 
iterator erase_after (iterator it)
 
void clear ()
 resets the list to empty
 
 SinglyLinkedList (const SinglyLinkedList &other)
 copy constructor
 
SinglyLinkedListoperator= (const SinglyLinkedList &other)
 copy assignment
 
 SinglyLinkedList (SinglyLinkedList &&other)
 move constructor
 
SinglyLinkedListoperator= (SinglyLinkedList &&other)
 move assignment
 
 ~SinglyLinkedList ()
 destructor
 

Friends

void swap (SinglyLinkedList &a, SinglyLinkedList &b)
 non-member function to swap two lists
 

Detailed Description

template<typename T>
class dsac::list::SinglyLinkedList< T >

singly linked list, akin to std::forward_list

Constructor & Destructor Documentation

◆ SinglyLinkedList() [1/3]

template<typename T >
dsac::list::SinglyLinkedList< T >::SinglyLinkedList ( )
inline

Constructs an empty list.

◆ SinglyLinkedList() [2/3]

template<typename T >
dsac::list::SinglyLinkedList< T >::SinglyLinkedList ( const SinglyLinkedList< T > &  other)
inline

copy constructor

◆ SinglyLinkedList() [3/3]

template<typename T >
dsac::list::SinglyLinkedList< T >::SinglyLinkedList ( SinglyLinkedList< T > &&  other)
inline

move constructor

◆ ~SinglyLinkedList()

template<typename T >
dsac::list::SinglyLinkedList< T >::~SinglyLinkedList ( )
inline

destructor

Here is the call graph for this function:

Member Function Documentation

◆ back() [1/2]

template<typename T >
T & dsac::list::SinglyLinkedList< T >::back ( )
inline

Returns live reference to the last element of the list; behavior undefined if list is empty

Returns
reference to last element of the list

◆ back() [2/2]

template<typename T >
const T & dsac::list::SinglyLinkedList< T >::back ( ) const
inline

Returns const reference to the last element of the list; behavior undefined if list is empty

Returns
reference to last element of the list

◆ begin() [1/2]

template<typename T >
iterator dsac::list::SinglyLinkedList< T >::begin ( )
inline

Returns iterator for the front of the list.

◆ begin() [2/2]

template<typename T >
const_iterator dsac::list::SinglyLinkedList< T >::begin ( ) const
inline

Returns const_iterator for the front of the list.

◆ clear()

template<typename T >
void dsac::list::SinglyLinkedList< T >::clear ( )
inline

resets the list to empty

Here is the call graph for this function:

◆ empty()

template<typename T >
bool dsac::list::SinglyLinkedList< T >::empty ( ) const
inline

Tests whether the list is empty.

Returns
true if the list is empty, false otherwise

◆ end() [1/2]

template<typename T >
iterator dsac::list::SinglyLinkedList< T >::end ( )
inline

Returns iterator for the end of the list.

◆ end() [2/2]

template<typename T >
const_iterator dsac::list::SinglyLinkedList< T >::end ( ) const
inline

Returns const_iterator for the end of the list.

◆ erase_after()

template<typename T >
iterator dsac::list::SinglyLinkedList< T >::erase_after ( iterator  it)
inline

Removes the element just after the given position

Parameters
ititerator defining position
Returns
iterator of position just beyond the removed element

◆ front() [1/2]

template<typename T >
T & dsac::list::SinglyLinkedList< T >::front ( )
inline

Returns live reference to the first element of the list; behavior undefined if list is empty

Returns
reference to first element of the list

◆ front() [2/2]

template<typename T >
const T & dsac::list::SinglyLinkedList< T >::front ( ) const
inline

Returns const reference to the first element of the list; behavior undefined if list is empty

Returns
reference to first element of the list

◆ insert_after()

template<typename T >
iterator dsac::list::SinglyLinkedList< T >::insert_after ( iterator  it,
const T &  elem 
)
inline

Inserts new element just after the given position

Parameters
ititerator defining position
elemelement to insert
Returns
iterator of newly inserted element

◆ operator=() [1/2]

template<typename T >
SinglyLinkedList & dsac::list::SinglyLinkedList< T >::operator= ( const SinglyLinkedList< T > &  other)
inline

copy assignment

Here is the call graph for this function:

◆ operator=() [2/2]

template<typename T >
SinglyLinkedList & dsac::list::SinglyLinkedList< T >::operator= ( SinglyLinkedList< T > &&  other)
inline

move assignment

◆ pop_front()

template<typename T >
void dsac::list::SinglyLinkedList< T >::pop_front ( )
inline

Removes the first element of the list; behavior undefined if list is empty.

◆ push_back()

template<typename T >
void dsac::list::SinglyLinkedList< T >::push_back ( const T &  elem)
inline

Inserts element at the end of the list

Parameters
elemthe new element

◆ push_front()

template<typename T >
void dsac::list::SinglyLinkedList< T >::push_front ( const T &  elem)
inline

Inserts element at the beginning of the list

Parameters
elemthe new element

◆ size()

template<typename T >
int dsac::list::SinglyLinkedList< T >::size ( ) const
inline

Returns the number of elements stored

Returns
the number of elements stored

Friends And Related Symbol Documentation

◆ swap

template<typename T >
void swap ( SinglyLinkedList< T > &  a,
SinglyLinkedList< T > &  b 
)
friend

non-member function to swap two lists


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