void PtrListRep::remove(void* element) { if(element!=NULL && _first!=NULL) { for(ListNode* n=_first; n!=NULL; n=n->getNext()) { void* el = n->getElement(); if(el==element) { // remove the node ListNode* prev = n->getPrevious(); ListNode* next = n->getNext(); if(prev!=NULL) prev->setNext(next); else // the node is the very first _first = next; if(next!=NULL) next->setPrevious(prev); else // the node is the last _last = prev; delete n; break; } } } }
void PtrListRep::add(void* element) { ListNode* n = new ListNode(element); if(_last==NULL) { // this is the very first one _first = _last = n; } else { // append to the end _last->setNext(n); n->setPrevious(_last); _last = n; } }
void MovieCollection::insert(Movie* data) { ListNode* p = new ListNode(data); if (firstNode == 0) //if we haven't got elements than this is our first { firstNode = p; lastNode = p; } else { ListNode* _currNode; for (_currNode = firstNode; _currNode != 0; _currNode = _currNode->getNext()) { if (_currNode->getData()->getTitle() < data->getTitle()) { if (_currNode->getNext() == 0) { p->insertAfter(_currNode); _currNode->setNext(p); lastNode = p; p->setPrevious(_currNode); //lastNode = lastNode->getNext(); // _currNode->setNext(p); } else if (_currNode->getNext()->getData()->getTitle() > data->getTitle()) { p->insertAfter(_currNode); _currNode->setNext(p); p->setPrevious(_currNode); } } } } m_listCount++; }