i cant seem to delete the last element from a simple linked list with this implementation. What am i missing?
void MyList<T>::deleteE(int poz) {
auto nCurent = head;
int lg = 0;
while (lg < poz || nCurent->next != nullptr) {
nCurent = nCurent->next;
lg++;
}
if (poz == 0) {
auto aux = this->head;
this->head = head->urm;
delete aux;
}
if (nCurent->next == nullptr) {
delete nCurent;
}
else {
auto aux = nCurent->next;
nCurent->next= aux->next;
delete aux;
}
}
Aucun commentaire:
Enregistrer un commentaire