|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Dynamic list of elements of type T.
More...
#include <tpl_dyn_slist_nc.H>
Classes | |
| class | Iterator |
| Iterator for Dyn_Slist_Nc. More... | |
Public Types | |
| typedef Snode_Nc< T > | Node |
Public Member Functions | |
| void | empty () |
| Empties the container. | |
| void | clear () noexcept |
| Alias for empty(). | |
| T & | insert (const T &data) |
| Insert an element at the beginning of the list. | |
| T & | append (const T &data) |
| Append an element at the end of the list. | |
| T & | get_first () |
| Returns a reference to the first element of the list. | |
| const T & | get_first () const |
| Returns a reference to the first element of the list (const version). | |
| T & | get_last () |
| Returns a reference to the last element of the list. | |
| const T & | get_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. | |
| T & | put (const T &item) |
If this is a queue, inserts the item item. | |
| T | get () |
| If this is a queue, extracts the oldest element. | |
| T & | rear () |
| If this is a queue, returns the youngest element. | |
| const T & | rear () const |
| Returns a reference to the youngest element (const version). | |
| T & | front () |
| If this is a queue, returns the oldest element. | |
| const T & | front () const |
| Returns a reference to the oldest element (const version). | |
| T & | push (const T &item) |
If this is a stack, inserts the item item. | |
| T | pop () |
| If this is a stack, removes the top element. | |
| T & | top () |
| If this is a stack, returns the top element. | |
| const T & | top () 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_Nc & | operator= (const Dyn_Slist_Nc &list) |
| Assignment operator with lvalue semantics. | |
| T & | operator[] (const size_t &n) |
Access element at index n. | |
| const T & | operator[] (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 () | |
| T & | get_data () |
| Returns a reference to the data contained in the node. | |
| const T & | get_data () const |
| Returns a reference to the data contained in the node (constant version). | |
| Snode_Nc * | remove_next () |
| Removes the node following this. | |
| Snode_Nc *& | get_next () |
| Returns the node following this. | |
| const Snode_Nc * | get_next () const |
| Returns the node following this (constant version). | |
Public Member Functions inherited from Aleph::Slink_Nc | |
| Slink_Nc () | |
| Empty constructor. | |
| Slink_Nc (const Slink_Nc &) | |
| Copy constructor; sets the next link to nullptr. | |
| ~Slink_Nc () | |
| Slink_Nc & | operator= (const Slink_Nc &link) |
| Assignment; sets the next link to nullptr. | |
| void | reset () |
| Resets the link to nullptr. | |
| bool | is_empty () const |
| Returns true if this is empty (points to nullptr). | |
| Slink_Nc *& | get_next () |
| Returns the next link. | |
| const Slink_Nc * | get_next () const |
| Returns the next link (constant version). | |
| void | insert (Slink_Nc *p) |
| Inserts link p after this. | |
| Slink_Nc * | remove_next () |
| Removes the link following this. | |
Private Attributes | |
| Node * | head |
| size_t | num_items |
Additional Inherited Members | |
Protected Attributes inherited from Aleph::Slink_Nc | |
| Slink_Nc * | next |
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.
| T | type of elements in the list. Semantic requirements for T:
|
Definition at line 69 of file tpl_dyn_slist_nc.H.
Definition at line 72 of file tpl_dyn_slist_nc.H.
|
inline |
|
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.
|
inline |
Destructor.
Empties the list.
Definition at line 280 of file tpl_dyn_slist_nc.H.
References Aleph::Dyn_Slist_Nc< T >::empty().
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.
| [in] | data | the item to be appended. |
| bad_alloc | if 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().
|
inlinenoexcept |
Alias for empty().
| none |
Definition at line 98 of file tpl_dyn_slist_nc.H.
References Aleph::Dyn_Slist_Nc< T >::empty().
|
inline |
Empties the container.
| none |
Definition at line 84 of file tpl_dyn_slist_nc.H.
References Aleph::divide_and_conquer_partition_dp(), Aleph::Slink_Nc::is_empty(), Aleph::Dyn_Slist_Nc< T >::num_items, Aleph::Snode_Nc< T >::remove_next(), and Aleph::Slink_Nc::reset().
Referenced by Aleph::Dyn_Slist_Nc< T >::~Dyn_Slist_Nc(), Aleph::Dyn_Slist_Nc< T >::clear(), and Aleph::Dyn_Slist_Nc< T >::operator=().
|
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().
Returns a reference to the oldest element (const version).
| underflow_error | if the list is empty. |
Definition at line 223 of file tpl_dyn_slist_nc.H.
References Aleph::Dyn_Slist_Nc< T >::get_first().
|
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().
|
inline |
Returns a reference to the first element of the list.
| underflow_error | if 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().
Returns a reference to the first element of the list (const version).
| underflow_error | if 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().
|
inline |
Returns a reference to the last element of the list.
| underflow_error | if 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().
Returns a reference to the last element of the list (const version).
| underflow_error | if 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 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.
| [in] | data | the item to be inserted. |
| bad_alloc | if 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().
|
inline |
Assignment operator with lvalue semantics.
Clears all elements from this and then copies all elements from list.
| [in] | list | the list to be assigned. |
this. | bad_alloc | if 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().
|
inline |
Access element at index n.
| [in] | n | index of 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.
|
inline |
Access element at index n (const version).
| [in] | n | index of 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.
|
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().
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().
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().
|
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().
Returns a reference to the youngest element (const version).
| underflow_error | if the list is empty. |
Definition at line 214 of file tpl_dyn_slist_nc.H.
References Aleph::Dyn_Slist_Nc< T >::get_last().
|
inline |
Removes the first element of the list and returns a copy of it.
| underflow_error | if 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().
|
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.
|
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().
Returns the top element (const version).
| underflow_error | if the list is empty. |
Definition at line 238 of file tpl_dyn_slist_nc.H.
References Aleph::Dyn_Slist_Nc< T >::get_first().
|
private |
Definition at line 75 of file tpl_dyn_slist_nc.H.
Referenced by Aleph::Dyn_Slist_Nc< T >::append(), Aleph::Dyn_Slist_Nc< T >::insert(), and Aleph::Dyn_Slist_Nc< T >::remove_first().
|
private |
Definition at line 76 of file tpl_dyn_slist_nc.H.
Referenced by Aleph::Dyn_Slist_Nc< T >::append(), Aleph::Dyn_Slist_Nc< T >::empty(), Aleph::Dyn_Slist_Nc< T >::insert(), Aleph::Dyn_Slist_Nc< T >::operator[](), Aleph::Dyn_Slist_Nc< T >::operator[](), Aleph::Dyn_Slist_Nc< T >::remove_first(), and Aleph::Dyn_Slist_Nc< T >::size().