6 # include <initializer_list>
7 # include <ahFunction.H>
8 # include <ahFunctional.H>
13 # define NEXT(p) (p->get_next())
50 throw std::invalid_argument(
"link is not empty");
105 : head(NULL), curr(NULL)
111 : head(&list), curr(head)
117 : head(_head), curr(_curr)
122 bool has_current()
const
127 bool has_curr()
const
129 return has_current();
134 if (not has_current())
135 throw std::overflow_error(
"Iterator is at the end of the list");
141 return get_current();
146 if (not has_current())
147 throw std::overflow_error(
"Iterator is at the end of the list");
159 template <
typename T>
180 std::swap(data, item);
272 std::swap(head, l.head);
273 std::swap(tail, l.tail);
280 I(NEXT(link) == NULL);
299 I(link != NULL and NEXT(link) == NULL);
327 l.head = l.tail = NULL;
350 NEXT(link) = list.head;
352 list.head = list.tail = NULL;
360 throw std::underflow_error(
"HTList is empty");
385 throw std::domain_error(
"Removing from a empty list");
394 for (
Slinknc * prev = head, * p = NEXT(head); p != NULL;
395 prev = p, p = NEXT(p))
398 NEXT(prev) = NEXT(p);
433 q = NEXT(q); ++
count;
435 if (q == tail or q == NULL)
439 q = NEXT(q); ++
count;
440 if (q == tail or q == NULL)
490 list.head = NEXT(link);
520 : lptr(it.lptr), curr(it.curr), prev(it.prev) { }
522 Iterator() : lptr(NULL), curr(NULL), prev(NULL) { }
525 : lptr(& (
HTList&) list), curr(lptr->head), prev(curr)
530 prev = curr = lptr->head;
533 void reset_first() { reset(); }
543 bool has_curr()
const {
return curr != NULL; }
545 bool has_current()
const {
return has_curr(); }
550 throw std::overflow_error(
"Iterator overflow");
555 Slinknc * get_current()
const {
return get_curr(); }
559 if (curr == lptr->head)
561 I(prev == lptr->head);
564 else if (curr == lptr->tail)
566 I(NEXT(prev) == curr);
571 I(NEXT(prev) == curr);
574 I(NEXT(prev) == curr);
581 throw std::overflow_error(
"Iterator overflow");
584 if (curr == lptr->head)
587 prev = curr = lptr->head;
589 else if (curr == lptr->tail)
591 I(NEXT(prev) == curr);
593 NEXT(prev) = NEXT(curr);
599 I(NEXT(prev) == curr);
601 NEXT(prev) = NEXT(curr);
612 insert(it.get_curr(), list);
619 cut(it.get_curr(), list);
626 for (Iterator it(*
this); it.has_curr(); it.next())
644 template <
typename T =
int>
659 T & __insert(Snodenc<T> * p)
662 return p->get_data();
665 T & __append(Snodenc<T> * p)
668 return p->get_data();
681 return __insert(
new Snodenc<T> (std::move(item)));
692 return __append(
new Snodenc<T> (std::move(item)));
712 T ret_val = std::move(p->
get_data());
724 throw std::underflow_error(
"List is empty");
733 throw std::underflow_error(
"List is empty");
739 const T & get_last()
const
741 return const_cast<DynList*
>(
this)->get_last();
744 T & get_first() {
return get(); }
746 const T & get_first()
const {
return get(); }
783 return ((
Snodenc<T>*) (HTList::Iterator::get_curr()))->get_data();
786 T & get_current()
const
794 T ret_val = std::move(p->
get_data());
803 template <
class Equal = Aleph::equal_to<T>>
804 bool remove(
const T & item)
806 for (
Iterator it(*
this); it.has_curr(); it.next())
807 if (Equal () (it.get_curr(), item))
829 DynList(std::initializer_list<T> l)
853 return (
DynList&) this->swap(l);
890 T &
get(
const size_t & i)
894 for (
size_t __i = 0 ; it.has_current() and __i < i; it.next(), ++__i);
896 return it.get_current();
899 T & operator [] (
const size_t & i)
906 Functional_Methods(T);
void insert(HTList &l)
Inserta toda la lista l antes de this; l deviene vacía.
Definition: htlist.H:340
Slinknc(const Slinknc &)
Constructor copia; coloca enlace a que apunte a NULL.
Definition: htlist.H:27
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Definition: ahAlgo.H:127
void reset()
Reinicia enlace a que apunte a NULL.
Definition: htlist.H:30
T remove_first()
Definition: htlist.H:719
Snodenc *& get_next()
Retorna el nodo siguiente a this.
Definition: htlist.H:193
Slinknc *& get_next()
Retorna el siguiente enlace.
Definition: htlist.H:58
void empty()
Elimina todos los elementos de la lista.
Definition: htlist.H:755
size_t reverse()
Invierte los elementos de la lista. Retorna el tamaño de la lista.
Definition: htlist.H:462
void cut_list(Slinknc *link, HTList &list)
Definition: htlist.H:498
void insert(Slinknc *link, HTList &list)
Definition: htlist.H:348
void put(Slinknc *link)
Inserta link al final de la lista.
Definition: htlist.H:331
void insert(DynList &&list)
Copia en tiempo constante los elementos de list al inicio de this.
Definition: htlist.H:863
size_t split(HTList &l, HTList &r)
Definition: htlist.H:456
void append(Slinknc *link)
Inserta link como último elemento.
Definition: htlist.H:297
void insert(Slinknc *link)
Inserta link como primer elemento.
Definition: htlist.H:278
Snodenc * remove_first()
Definition: htlist.H:202
Slinknc * pop()
Elimina el primer elemento de this.
Definition: htlist.H:409
DynList(T &&item)
Crea una lista con elemento item.
Definition: htlist.H:702
DynList(DynList &&l)
Crea una lista copia de l.
Definition: htlist.H:824
T & get_data()
Retorna una referencia al dato contenido en el nodo.
Definition: htlist.H:167
Slinknc * get_last()
Retorna el último elemento de la lista.
Definition: htlist.H:266
bool is_empty() const
Retorna true si la lista está vacía.
Definition: htlist.H:248
HTList & swap(HTList &l)
Definition: htlist.H:270
bool is_unitarian_or_empty() const
Retorna true si la lista tiene un elemento o está vacía.
Definition: htlist.H:254
void concat_list(HTList &l)
Definition: htlist.H:337
Slinknc * get_head()
Retorna la cabeza de la lista (el primer elemento)
Definition: htlist.H:257
T & insert(const T &item)
Inserta un item como primer elemento.
Definition: htlist.H:674
Snodenc()
Constructor vacío.
Definition: htlist.H:170
Snodenc(const T &item)
Constructor que copia dato.
Definition: htlist.H:173
Snodenc * remove_next()
Definition: htlist.H:190
Slinknc * get_tail()
Retorna la cola de la lista (el último elemento)
Definition: htlist.H:260
Slinknc & operator=(const Slinknc &link)
Asignación; coloca enlace a que apunte a NULL.
Definition: htlist.H:44
Operation for_each(Itor beg, const Itor &end, Operation op)
Definition: ahAlgo.H:83
Slinknc * get_first()
Retorna el primer elemento de la lista.
Definition: htlist.H:263
Slinknc()
Constructor vacío.
Definition: htlist.H:24
Recorre condicionalmente el contenedor y ejecuta una operation mientras ésta retorne true...
void remove_all_and_delete()
Definition: htlist.H:502
void insert(Slinknc *p)
Definition: htlist.H:71
bool is_empty() const
Retorna true si this está vacío (apunta a NULL)
Definition: htlist.H:37
void cut(Slinknc *link, HTList &list)
Definition: htlist.H:486
Snodenc *& get_first() const
Retorna el nodo siguiente a this.
Definition: htlist.H:205
void insert(const DynList &list)
Definition: htlist.H:881
DynList(const DynList &l)
Crea una lista copia de l.
Definition: htlist.H:817
size_t split_list(HTList &l, HTList &r)
Definition: htlist.H:415
bool is_unitarian() const
Retorna true si la lista contiene exactamente un solo elemento.
Definition: htlist.H:251
DynList & operator=(const DynList &l)
Copia a this los elementos de l.
Definition: htlist.H:838
Slinknc * remove_first()
Elimina el primer elemento de this.
Definition: htlist.H:378
void cut_list(const Iterator &it, HTList &list)
Definition: htlist.H:617
Slinknc * remove_head()
Definition: htlist.H:357
Slinknc * remove_next()
Definition: htlist.H:88
HTList(Slinknc *l)
Inicializa una lista de un solo Slinknc.
Definition: htlist.H:245
void concat(HTList &l)
Concatena a this toda la lista l; l deviene vacía.
Definition: htlist.H:334
void append(DynList &&list)
Copia en tiempo constante los elementos de list al final de this.
Definition: htlist.H:857
T & append(const T &item)
Inserta un item como último elemento.
Definition: htlist.H:685
size_t reverse_list()
Definition: htlist.H:479
void append(const DynList &list)
Definition: htlist.H:870
void append(HTList &l)
Definition: htlist.H:314
HTList()
Inicializa una lista vacía.
Definition: htlist.H:242
DynList(const T &item)
Crea una lista con elemento item.
Definition: htlist.H:696
void push(Slinknc *link)
Inserta link como primer elemento.
Definition: htlist.H:294