Skip to content

Instantly share code, notes, and snippets.

@jryebread
Last active June 15, 2017 19:33
Show Gist options
  • Save jryebread/fd4835b89bd0f84c973ee34bfbce5971 to your computer and use it in GitHub Desktop.
Save jryebread/fd4835b89bd0f84c973ee34bfbce5971 to your computer and use it in GitHub Desktop.
template<class T>
void LinkedList<T>::deleteElement(T currVal)
{
Node<T> *p = Head;
//Stop at the node before the one you want to delete
while (p->next->data != currVal)
{
p = p->next;
}
//set up the next node for deletion
Node<T> *delptr = p->next;
//reset pointers
p->next = p->next->next;
p = p->next;
p->prev = p->prev->prev;
//delete the node
delete delptr;
}
//helper function
template<class T>
Node<T> *LinkedList<T>::getNode(T value)
{
Node<T> *curr = Head;
while (curr != nullptr) {
if (curr->data == value)
return curr;
curr = curr->next;
}
return nullptr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment