Код: Выделить всё
// These operations have to find the previous node of the position, so it costs O(n).
node* erase(node* head, int pos);
node* erase(node* node_to_delete);
// This operation costs O(1), but it affect the validation of the reference of the next node.
node* erase(node* position) {
if (position == _last)
return _last;
auto tmp = position -> next;
position -> val = position -> next -> val;
position -> next = position -> next -> next;
delete tmp;
if (tmp == _last)
_last = position;
_size--;
return position;
}
Подробнее здесь: https://stackoverflow.com/questions/782 ... t-costs-o1