This is my current code. The code is to remove the element in the list "head" that is "e". The code works if there is only one element in the list but if there are more than 1 element in the list, it doesn't work. The function should return true if there is an element that equals "e" and then it removes it and false if no element equals "e".
bool StringLinkedList::remove(const std::string& e){
StringNode* current = head;
int i = 0;
if (current == NULL)
returnfalse;
while (current != NULL){
if (current->elem == e){
current = current->next;
head = head->next;
i++;
}
else{
current = current->next;
}
}
if (i > 0){
n--;
returntrue;
}
else{
returnfalse;
}
}