I have a really weird bug in my program. Im working with linked list in this program. The ead->next does show up as nullptr but the if statement is skipped. The weird part is that it doesn't go to the else statement after that. I got this info from stepping through the debugger. I marked the part of the function that holds the bug. Any reason why this is happening? I thought there was something wrong with the compiler but my program was tested on my class server and had the same problem.
void linked::deletetype(string what, node* ead) {
if (ead == nullptr) {
return;
}
else if (ead->type == what && ead->previous == nullptr) {
// it enters here
if (ead->next == nullptr) {// this is suppose to be true but it skips
ead == nullptr;
head == nullptr;
}
else {//even though it skips the if statment doesn't go to the else statement.
ead = ead->next;
ead->previous = nullptr;
head = ead;
}
// programs completely skips over else
}
else if (ead->type == what&&ead->next!=nullptr) {
ead->previous->next = ead->next;
ead->next->previous = ead->previous;
}
else if (ead->type == what && ead->next == nullptr) {
ead = ead->previous;
ead->next = nullptr;
tail = ead;
}
deletetype(what, ead->next);
}
Aucun commentaire:
Enregistrer un commentaire