bool List::member(ICollectible *c) const{ for(ListNode *current = head; current != NULL; current = current->getNext()) if(current->getElem() == c) return true; return false; }
void List::remove(ICollectible *c) { ListNode *current = head; ListNode *previous = NULL; while(current != NULL && current->getElem() != c){ previous = current; current = current->getNext(); } if(current == NULL){ // final de la lista, no estaba return; } else if(current->getElem() == c){ // ya está, se borra --size; if(previous == NULL) // se borra el primer elemento head = current->getNext(); else previous->setNext(current->getNext()); delete current; } }
void List::add(ICollectible* c) { if(head == NULL){ // list vacía; tamaño = 1 head = new ListNode(c); size = 1; return; } ListNode *current = head; ListNode *previous; while(current != NULL && current->getElem() != c){ previous = current; current = current->getNext(); } if(current == NULL){ // final de la lista, se agrega previous->setNext(new ListNode(c)); ++size; } }