int List::deleteLast() { if (currentSize != 0) { int tmp = last->getContent(); ListItem *del = last; last = del->getPrevious(); delete del; currentSize--; return tmp; } else return 0; }
void List::insertElementAt(int i, int pos) { if (pos <= 0) prependElement(i); else if (pos >= getSize()) appendElement(i); else { ListItem *tmp = first; while (pos-- > 0) { tmp = tmp->getNext(); } new ListItem(tmp->getPrevious(), tmp, i); currentSize++; } }
void List::insertElementAt(int i, int pos) { if (pos <= 0) { prependElement(i); } else if (pos >= getSize()) { appendElement(i); } else { ListItem* p = first; // iterate over elements while (pos-- > 0) { p = p->getNext(); } new ListItem(p->getPrevious(), p, i); ++currentSize; } }