void remove (const T &val) {
node* placer = head->next;
node* prev_placer = head;
while (placer) {
if (placer->data == val) {
prev_placer->next = placer->next;
free(placer);
}
prev_placer = placer;
placer = placer->next;
}
if (head->data == val) {
this->head = head->next;
head->prev = nullptr;
}
if (tail->data = val) {
this->tail = tail->prev;
tail->next = nullptr;
}
}
An eexample: If my list was [h, e, l, l, o], and I wanted to remove('l')
, then my list == [h, e, o]. However, whenever I try to print my work to test it, I keep getting segmentation faults.