1 # ifndef TPL_DYNDLIST_H
2 # define TPL_DYNDLIST_H
4 # include <ahFunctional.H>
6 # include <tpl_dnode.H>
25 template <
typename T =
int>
41 const size_t &
size()
const {
return num_elem; }
86 T &
insert(
const T & item)
throw(std::exception, std::bad_alloc)
88 return __insert(
new Dnode<T> (item));
93 return __insert(
new Dnode<T> (std::move(item)));
106 T &
append(
const T & item)
throw(std::exception, std::bad_alloc)
108 return __append(
new Dnode<T> (item));
111 T &
append(T && item) throw(std::exception, std::bad_alloc)
113 return __append(
new Dnode<T> (std::move(item)));
134 num_elem += list.num_elem;
145 num_elem +=
list.num_elem;
171 num_elem += list.num_elem;
182 num_elem +=
list.num_elem;
191 T &
get_first() throw(std::exception, std::underflow_error)
193 return this->
get_next()->get_data();
196 const T &
get_first()
const throw(std::exception, std::underflow_error)
202 T &
get_last() throw(std::exception, std::underflow_error)
204 return this->
get_prev()->get_data();
207 const T &
get_last()
const throw(std::exception, std::underflow_error)
247 T &
put(T && item) {
return append(std::move(item)); }
272 void remove(T & data)
297 std::swap(num_elem, l.num_elem);
298 this->Dlink::swap(&l);
314 throw(std::exception, std::domain_error)
316 if ((not l.is_empty()) or (not r.is_empty()))
317 throw std::domain_error(
"lists are not empty");
320 l.num_elem = r.num_elem = num_elem/2;
322 if (num_elem % 2 == 1)
392 pos = list_ptr->num_elem - 1;
406 list_ptr(&const_cast<
DynDlist<T>&>(_list)), pos(0)
420 list_ptr = it.list_ptr;
449 throw(std::exception, std::overflow_error, std::bad_alloc)
452 throw std::overflow_error (
"DynDlist Iterator has not current");
455 ++list_ptr->num_elem;
459 throw(std::exception, std::overflow_error, std::bad_alloc)
462 throw std::overflow_error (
"DynDlist Iterator has not current");
466 ++list_ptr->num_elem;
480 throw(std::exception, std::overflow_error, std::bad_alloc)
483 throw std::overflow_error (
"DynDlist Iterator has not current");
486 ++list_ptr->num_elem;
490 throw(std::exception, std::overflow_error, std::bad_alloc)
493 throw std::overflow_error (
"DynDlist Iterator has not current");
497 ++list_ptr->num_elem;
517 throw(std::exception, std::overflow_error)
521 throw std::overflow_error (
"DynDlist Iterator has not current");
524 list_ptr->num_elem +=
list.num_elem;
547 throw(std::exception, std::overflow_error)
550 throw std::overflow_error (
"DynDlist Iterator has not current");
553 list_ptr->num_elem +=
list.num_elem;
568 T
del() throw(std::exception, std::overflow_error)
571 throw std::overflow_error (
"DynDlist Iterator has not current");
578 --list_ptr->num_elem;
595 throw std::overflow_error (
"DynDlist Iterator has not current");
601 --list_ptr->num_elem;
620 throw std::overflow_error (
"DynDlist Iterator has not current");
626 --list_ptr->num_elem;
655 throw std::overflow_error (
"DynDlist Iterator has not current");
658 list.num_elem = list_ptr->num_elem - pos;
659 list_ptr->num_elem -= pos;
661 return list.num_elem;
684 this->
append(itor.get_current());
699 this->
append(itor.get_current());
709 DynDlist(std::initializer_list<T> l)
732 T & operator [] (
const size_t & n)
736 for (
int i = 0; i < n and it.has_current(); i++, it.next()) ;
738 return it.get_current();
743 Functional_Methods(T);
void swap(DynDlist &l)
Definition: tpl_dynDlist.H:295
T & rear()
Si this e suna cola, entonces retorna el elemento más joven.
Definition: tpl_dynDlist.H:253
DynDlist< T > & operator=(const DynDlist &list)
Definition: tpl_dynDlist.H:673
const int & reset_last()
Definition: tpl_dynDlist.H:389
T & get_curr() const
Retorna el elemento actual del iterador.
Definition: tpl_dynDlist.H:433
const int & prev()
Definition: tpl_dynDlist.H:364
Definition: tpl_dynDlist.H:26
Dnode< T > * remove_next()
Elimina sucesor a this y retorna su dirección.
Definition: tpl_dnode.H:37
~DynDlist()
Destructor.
Definition: tpl_dynDlist.H:53
T & front()
Si this e suna cola, entonces retorna el elemento más antiguo.
Definition: tpl_dynDlist.H:256
const int & next()
Definition: tpl_dynDlist.H:352
T & put(const T &item)
Si this es una cola, entonces mete el elemento item.
Definition: tpl_dynDlist.H:245
const size_t & size() const
Retorna la cantidad de elemento que tiene la lista.
Definition: tpl_dynDlist.H:41
T & push(const T &item)
Si this es una pila, entonces inserta item.
Definition: tpl_dynDlist.H:259
T pop()
Si this es una pila, entonces elimina el tope.
Definition: tpl_dynDlist.H:265
const int & reset_first()
Definition: tpl_dynDlist.H:376
size_t cut_list(DynDlist &list)
Definition: tpl_dynDlist.H:652
Iterator(const DynDlist< T > &_list)
Constructor de iterador sobre lista constante _list.
Definition: tpl_dynDlist.H:404
Definition: tpl_dynDlist.H:332
T & push(T &&item)
Si this es una pila, entonces inserta item.
Definition: tpl_dynDlist.H:262
DynDlist(DynDlist< T > &&list)
Definition: tpl_dynDlist.H:704
Dnode< T > *& get_next()
Retorna referencia a puntero de nodo siguiente a this.
Definition: tpl_dnode.H:28
T remove_last()
Definition: tpl_dynDlist.H:234
DynDlist Set_Type
El tipo de conjunto sobre el cual se itera.
Definition: tpl_dynDlist.H:339
Operation for_each(Itor beg, const Itor &end, Operation op)
Definition: ahAlgo.H:83
T & get_first()
Retorna una referencia al primer elemento de la lista.
Definition: tpl_dynDlist.H:191
T Item_Type
El tipo de elemento que alberga el conjunto.
Definition: tpl_dynDlist.H:36
bool has_current() const
Retorna true si iterador aún tiene elemento actual.
Definition: dlink.H:554
void insert(const T &item)
Definition: tpl_dynDlist.H:448
void empty()
Vacía todos los elementos de la lista.
Definition: tpl_dynDlist.H:45
void append_list(Dlink *head)
Definition: dlink.H:231
Iterator & operator=(const Iterator &it)
Asignación e iterador.
Definition: tpl_dynDlist.H:417
T remove_next()
Definition: tpl_dynDlist.H:616
size_t split_list(Dlink &l, Dlink &r)
Definition: dlink.H:372
void insert_list(const DynDlist &list)
Definition: tpl_dynDlist.H:516
const int & get_pos() const
retorna la posición ordinal del elemento actual de iterador.
Definition: tpl_dynDlist.H:345
T remove_prev()
Definition: tpl_dynDlist.H:592
Dnode< T > *& get_prev()
Retorna referencia a puntero de nodo previo a this.
Definition: tpl_dnode.H:31
T Item_Type
El tipo de elemento que retorna get_current().
Definition: tpl_dynDlist.H:342
DynDlist(const DynDlist &list)
Constructor copia; todos los elementos de this son copiados.
Definition: tpl_dynDlist.H:690
Dnode< T > * remove_prev()
Elimina anterior a this y retorna su dirección.
Definition: tpl_dnode.H:34
void reset_first()
Reinicia iterador a primer nodo de la lista.
Definition: dlink.H:494
void split_list(DynDlist &l, DynDlist &r)
Definition: tpl_dynDlist.H:313
void append_list(const DynDlist &list)
Definition: tpl_dynDlist.H:546
T & get_last()
Retorna una referencia al último elemento de la lista.
Definition: tpl_dynDlist.H:202
T & top() const
Si this es una pila, entonces retorna el tope.
Definition: tpl_dynDlist.H:268
void prev()
Retrocede iterador en una posición.
Definition: dlink.H:584
void erase(T &data)
Definition: tpl_dynDlist.H:282
size_t insert_list(const DynDlist &list)
Definition: tpl_dynDlist.H:131
Dnode< T > * get_current() const
retorna puntero al nodo actual
Definition: tpl_dnode.H:181
size_t append_list(DynDlist &list)
Definition: tpl_dynDlist.H:168
T & get_current() const
Retorna el elemento actual del iterador.
Definition: tpl_dynDlist.H:427
DynDlist Set_Type
El tipo de conjunto sobre el cual se itera.
Definition: tpl_dynDlist.H:33
Iterator & operator=(Dnode *head)
Asigna al iterador la lista apuntada por head */.
Definition: tpl_dnode.H:175
void append(Dlink *node)
Definition: dlink.H:166
void reset_last()
Reinicia iterador a último nodo de la lista.
Definition: dlink.H:501
void insert_list(Dlink *head)
Definition: dlink.H:210
bool is_empty() const
retorna true si this está vacía
Definition: dlink.H:127
T del()
Definition: tpl_dynDlist.H:568
T remove_first()
Definition: tpl_dynDlist.H:218
void reset()
Reinicia dlink (equivalente a que se vacíe la lista)
Definition: dlink.H:77
void append(const T &item)
Definition: tpl_dynDlist.H:479
Iterator(DynDlist< T > &_list)
Constructor de iterador sobre lista _list.
Definition: tpl_dynDlist.H:397
T & insert(const T &item)
Definition: tpl_dynDlist.H:86
void del()
Elimina this de su contexto en una lista.
Definition: dlink.H:278
void insert(Dlink *node)
Definition: dlink.H:140
void next()
Avanza iterador en una posición.
Definition: dlink.H:593
T & get_data()
Retorna referencia a dato contenido en el nodo.
Definition: tpl_dnode.H:126
T & append(const T &item)
Definition: tpl_dynDlist.H:106
Nodo perteneciente a lista doblemente enlazada circular.
Definition: tpl_dnode.H:19