Last active
June 15, 2017 19:33
-
-
Save jryebread/fd4835b89bd0f84c973ee34bfbce5971 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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