Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Dyn_Slist_Nc< T > Class Template Reference

Dynamic list of elements of type T. More...

#include <tpl_dyn_slist_nc.H>

Inheritance diagram for Aleph::Dyn_Slist_Nc< T >:
[legend]
Collaboration diagram for Aleph::Dyn_Slist_Nc< T >:
[legend]

Classes

class  Iterator
 Iterator for Dyn_Slist_Nc. More...
 

Public Types

typedef Snode_Nc< TNode
 

Public Member Functions

void empty ()
 Empties the container.
 
void clear () noexcept
 Alias for empty().
 
Tinsert (const T &data)
 Insert an element at the beginning of the list.
 
Tappend (const T &data)
 Append an element at the end of the list.
 
Tget_first ()
 Returns a reference to the first element of the list.
 
const Tget_first () const
 Returns a reference to the first element of the list (const version).
 
Tget_last ()
 Returns a reference to the last element of the list.
 
const Tget_last () const
 Returns a reference to the last element of the list (const version).
 
T remove_first ()
 Removes the first element of the list and returns a copy of it.
 
Tput (const T &item)
 If this is a queue, inserts the item item.
 
T get ()
 If this is a queue, extracts the oldest element.
 
Trear ()
 If this is a queue, returns the youngest element.
 
const Trear () const
 Returns a reference to the youngest element (const version).
 
Tfront ()
 If this is a queue, returns the oldest element.
 
const Tfront () const
 Returns a reference to the oldest element (const version).
 
Tpush (const T &item)
 If this is a stack, inserts the item item.
 
T pop ()
 If this is a stack, removes the top element.
 
Ttop ()
 If this is a stack, returns the top element.
 
const Ttop () const
 Returns the top element (const version).
 
const size_t & size () const
 Returns the number of elements in the list.
 
 Dyn_Slist_Nc ()
 Default constructor.
 
 Dyn_Slist_Nc (const Dyn_Slist_Nc &l)
 Copy constructor.
 
 ~Dyn_Slist_Nc ()
 Destructor.
 
Dyn_Slist_Ncoperator= (const Dyn_Slist_Nc &list)
 Assignment operator with lvalue semantics.
 
Toperator[] (const size_t &n)
 Access element at index n.
 
const Toperator[] (const size_t &n) const
 Access element at index n (const version).
 
- Public Member Functions inherited from Aleph::Snode_Nc< T >
 Snode_Nc ()
 Empty constructor.
 
 Snode_Nc (const T &_data)
 Constructor that copies data.
 
 ~Snode_Nc ()
 
Tget_data ()
 Returns a reference to the data contained in the node.
 
const Tget_data () const
 Returns a reference to the data contained in the node (constant version).
 
Snode_Ncremove_next ()
 Removes the node following this.
 
Snode_Nc *& get_next ()
 Returns the node following this.
 
const Snode_Ncget_next () const
 Returns the node following this (constant version).
 

Private Attributes

Nodehead
 
size_t num_items
 

Additional Inherited Members

Detailed Description

template<typename T>
class Aleph::Dyn_Slist_Nc< T >

Dynamic list of elements of type T.

Dyn_Slist_Nc<T> defines a dynamic list, which is a sequence of elements of some type T.

This type can be used as a stack or a queue.

Template Parameters
Ttype of elements in the list. Semantic requirements for T:
  • T must be Destructible and CopyConstructible (or Copyable) because operations like insert(), append(), copy construction, assignment of the Dyn_Slist_Nc<T> container, and element destruction rely on these properties.
  • Move-only types are currently not supported.
  • Destructors of T should ideally be noexcept.
See also
Slink, Snode_Nc, Dyn_Slist_Nc::Iterator
Author
Leandro R. León
Alejandro J. Mujica

Definition at line 69 of file tpl_dyn_slist_nc.H.

Member Typedef Documentation

◆ Node

Definition at line 72 of file tpl_dyn_slist_nc.H.

Constructor & Destructor Documentation

◆ Dyn_Slist_Nc() [1/2]

template<typename T >
Aleph::Dyn_Slist_Nc< T >::Dyn_Slist_Nc ( )
inline

Default constructor.

Creates an empty list.

Definition at line 266 of file tpl_dyn_slist_nc.H.

◆ Dyn_Slist_Nc() [2/2]

template<typename T >
Aleph::Dyn_Slist_Nc< T >::Dyn_Slist_Nc ( const Dyn_Slist_Nc< T > &  l)
inline

Copy constructor.

Definition at line 272 of file tpl_dyn_slist_nc.H.

References Aleph::Dyn_Slist_Nc< T >::append(), Aleph::Slink_Nc::Iterator::has_curr(), and l.

◆ ~Dyn_Slist_Nc()

template<typename T >
Aleph::Dyn_Slist_Nc< T >::~Dyn_Slist_Nc ( )
inline

Destructor.

Empties the list.

Definition at line 280 of file tpl_dyn_slist_nc.H.

References Aleph::Dyn_Slist_Nc< T >::empty().

Member Function Documentation

◆ append()

template<typename T >
T & Aleph::Dyn_Slist_Nc< T >::append ( const T data)
inline

Append an element at the end of the list.

Inserts a copy of data as the last element of this list. After the operation, the last element of the list is data.

Parameters
[in]datathe item to be appended.
Returns
reference to the newly inserted item.
Exceptions
bad_allocif there is no memory for the new element.

Definition at line 129 of file tpl_dyn_slist_nc.H.

References Aleph::Snode_Nc< T >::data, Aleph::divide_and_conquer_partition_dp(), Aleph::Snode_Nc< T >::get_data(), Aleph::Dyn_Slist_Nc< T >::head, Aleph::Slink_Nc::insert(), and Aleph::Dyn_Slist_Nc< T >::num_items.

Referenced by Aleph::Dyn_Slist_Nc< T >::Dyn_Slist_Nc(), Aleph::Dyn_Slist_Nc< T >::operator=(), and Aleph::Dyn_Slist_Nc< T >::put().

◆ clear()

template<typename T >
void Aleph::Dyn_Slist_Nc< T >::clear ( )
inlinenoexcept

Alias for empty().

Exceptions
none
See also
empty()

Definition at line 98 of file tpl_dyn_slist_nc.H.

References Aleph::Dyn_Slist_Nc< T >::empty().

◆ empty()

◆ front() [1/2]

template<typename T >
T & Aleph::Dyn_Slist_Nc< T >::front ( )
inline

If this is a queue, returns the oldest element.

Definition at line 217 of file tpl_dyn_slist_nc.H.

References Aleph::Dyn_Slist_Nc< T >::get_first().

◆ front() [2/2]

template<typename T >
const T & Aleph::Dyn_Slist_Nc< T >::front ( ) const
inline

Returns a reference to the oldest element (const version).

Returns
constant reference to the oldest element.
Exceptions
underflow_errorif the list is empty.

Definition at line 223 of file tpl_dyn_slist_nc.H.

References Aleph::Dyn_Slist_Nc< T >::get_first().

◆ get()

template<typename T >
T Aleph::Dyn_Slist_Nc< T >::get ( )
inline

If this is a queue, extracts the oldest element.

Definition at line 205 of file tpl_dyn_slist_nc.H.

References Aleph::Dyn_Slist_Nc< T >::remove_first().

◆ get_first() [1/2]

template<typename T >
T & Aleph::Dyn_Slist_Nc< T >::get_first ( )
inline

Returns a reference to the first element of the list.

Returns
reference to the first element.
Exceptions
underflow_errorif the list is empty.

Definition at line 144 of file tpl_dyn_slist_nc.H.

References ah_underflow_error_if, Aleph::Snode_Nc< T >::get_data(), Aleph::Snode_Nc< T >::get_next(), and Aleph::Slink_Nc::is_empty().

Referenced by Aleph::Dyn_Slist_Nc< T >::front(), Aleph::Dyn_Slist_Nc< T >::front(), Aleph::Dyn_Slist_Nc< T >::top(), and Aleph::Dyn_Slist_Nc< T >::top().

◆ get_first() [2/2]

template<typename T >
const T & Aleph::Dyn_Slist_Nc< T >::get_first ( ) const
inline

Returns a reference to the first element of the list (const version).

Returns
reference to the first element.
Exceptions
underflow_errorif the list is empty.

Definition at line 155 of file tpl_dyn_slist_nc.H.

References ah_underflow_error_if, Aleph::Snode_Nc< T >::get_data(), Aleph::Snode_Nc< T >::get_next(), and Aleph::Slink_Nc::is_empty().

◆ get_last() [1/2]

template<typename T >
T & Aleph::Dyn_Slist_Nc< T >::get_last ( )
inline

Returns a reference to the last element of the list.

Returns
reference to the last element.
Exceptions
underflow_errorif the list is empty.

Definition at line 166 of file tpl_dyn_slist_nc.H.

References ah_underflow_error_if, Aleph::Snode_Nc< T >::get_data(), and Aleph::Slink_Nc::is_empty().

Referenced by Aleph::Dyn_Slist_Nc< T >::rear(), and Aleph::Dyn_Slist_Nc< T >::rear().

◆ get_last() [2/2]

template<typename T >
const T & Aleph::Dyn_Slist_Nc< T >::get_last ( ) const
inline

Returns a reference to the last element of the list (const version).

Returns
reference to the last element.
Exceptions
underflow_errorif the list is empty.

Definition at line 177 of file tpl_dyn_slist_nc.H.

References ah_underflow_error_if, Aleph::Snode_Nc< T >::get_data(), and Aleph::Slink_Nc::is_empty().

◆ insert()

template<typename T >
T & Aleph::Dyn_Slist_Nc< T >::insert ( const T data)
inline

Insert an element at the beginning of the list.

Inserts a copy of data as the first element of this list. After the operation, the first element of the list is data.

Parameters
[in]datathe item to be inserted.
Returns
reference to the newly inserted item.
Exceptions
bad_allocif there is no memory for the new element.

Definition at line 109 of file tpl_dyn_slist_nc.H.

References Aleph::Snode_Nc< T >::data, Aleph::Snode_Nc< T >::get_data(), Aleph::Dyn_Slist_Nc< T >::head, Aleph::Slink_Nc::insert(), and Aleph::Dyn_Slist_Nc< T >::num_items.

Referenced by Aleph::Dyn_Slist_Nc< T >::push().

◆ operator=()

template<typename T >
Dyn_Slist_Nc & Aleph::Dyn_Slist_Nc< T >::operator= ( const Dyn_Slist_Nc< T > &  list)
inline

Assignment operator with lvalue semantics.

Clears all elements from this and then copies all elements from list.

Parameters
[in]listthe list to be assigned.
Returns
reference to this.
Exceptions
bad_allocif there is no memory.

Definition at line 293 of file tpl_dyn_slist_nc.H.

References Aleph::Dyn_Slist_Nc< T >::append(), Aleph::divide_and_conquer_partition_dp(), Aleph::Dyn_Slist_Nc< T >::empty(), Aleph::Slink_Nc::Iterator::has_curr(), and Aleph::Slink_Nc::is_empty().

◆ operator[]() [1/2]

template<typename T >
T & Aleph::Dyn_Slist_Nc< T >::operator[] ( const size_t &  n)
inline

Access element at index n.

Parameters
[in]nindex of the element.
Returns
reference to the element.

Definition at line 313 of file tpl_dyn_slist_nc.H.

References ah_range_error_if, Aleph::Dyn_Slist_Nc< T >::Iterator::get_curr(), Aleph::Slink_Nc::Iterator::next_ne(), and Aleph::Dyn_Slist_Nc< T >::num_items.

◆ operator[]() [2/2]

template<typename T >
const T & Aleph::Dyn_Slist_Nc< T >::operator[] ( const size_t &  n) const
inline

Access element at index n (const version).

Parameters
[in]nindex of the element.
Returns
reference to the element.

Definition at line 327 of file tpl_dyn_slist_nc.H.

References ah_range_error_if, Aleph::Dyn_Slist_Nc< T >::Iterator::get_curr(), Aleph::Slink_Nc::Iterator::next_ne(), and Aleph::Dyn_Slist_Nc< T >::num_items.

◆ pop()

template<typename T >
T Aleph::Dyn_Slist_Nc< T >::pop ( )
inline

If this is a stack, removes the top element.

Definition at line 229 of file tpl_dyn_slist_nc.H.

References Aleph::Dyn_Slist_Nc< T >::remove_first().

◆ push()

template<typename T >
T & Aleph::Dyn_Slist_Nc< T >::push ( const T item)
inline

If this is a stack, inserts the item item.

Definition at line 226 of file tpl_dyn_slist_nc.H.

References Aleph::Dyn_Slist_Nc< T >::insert().

◆ put()

template<typename T >
T & Aleph::Dyn_Slist_Nc< T >::put ( const T item)
inline

If this is a queue, inserts the item item.

Definition at line 202 of file tpl_dyn_slist_nc.H.

References Aleph::Dyn_Slist_Nc< T >::append().

◆ rear() [1/2]

template<typename T >
T & Aleph::Dyn_Slist_Nc< T >::rear ( )
inline

If this is a queue, returns the youngest element.

Definition at line 208 of file tpl_dyn_slist_nc.H.

References Aleph::Dyn_Slist_Nc< T >::get_last().

◆ rear() [2/2]

template<typename T >
const T & Aleph::Dyn_Slist_Nc< T >::rear ( ) const
inline

Returns a reference to the youngest element (const version).

Returns
constant reference to the youngest element.
Exceptions
underflow_errorif the list is empty.

Definition at line 214 of file tpl_dyn_slist_nc.H.

References Aleph::Dyn_Slist_Nc< T >::get_last().

◆ remove_first()

template<typename T >
T Aleph::Dyn_Slist_Nc< T >::remove_first ( )
inline

Removes the first element of the list and returns a copy of it.

Returns
a copy of the removed element.
Exceptions
underflow_errorif the list is empty.

Definition at line 189 of file tpl_dyn_slist_nc.H.

References ah_underflow_error_if, Aleph::divide_and_conquer_partition_dp(), Aleph::Snode_Nc< T >::get_data(), Aleph::Dyn_Slist_Nc< T >::head, Aleph::Slink_Nc::is_empty(), Aleph::Dyn_Slist_Nc< T >::num_items, and Aleph::Snode_Nc< T >::remove_next().

Referenced by Aleph::Dyn_Slist_Nc< T >::get(), and Aleph::Dyn_Slist_Nc< T >::pop().

◆ size()

template<typename T >
const size_t & Aleph::Dyn_Slist_Nc< T >::size ( ) const
inline

Returns the number of elements in the list.

Definition at line 242 of file tpl_dyn_slist_nc.H.

References Aleph::Dyn_Slist_Nc< T >::num_items.

◆ top() [1/2]

template<typename T >
T & Aleph::Dyn_Slist_Nc< T >::top ( )
inline

If this is a stack, returns the top element.

Definition at line 232 of file tpl_dyn_slist_nc.H.

References Aleph::Dyn_Slist_Nc< T >::get_first().

◆ top() [2/2]

template<typename T >
const T & Aleph::Dyn_Slist_Nc< T >::top ( ) const
inline

Returns the top element (const version).

Returns
constant reference to the top element.
Exceptions
underflow_errorif the list is empty.

Definition at line 238 of file tpl_dyn_slist_nc.H.

References Aleph::Dyn_Slist_Nc< T >::get_first().

Member Data Documentation

◆ head

◆ num_items


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