Created
March 14, 2020 05:03
-
-
Save rajkumar-p/f7c60f4a98dba2a84b7c3d708bd5b57f to your computer and use it in GitHub Desktop.
Check for an element in fine-grained list
This file contains hidden or 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<typename T> | |
| bool SortedList<T>::exists(T elem) | |
| { | |
| NodeListWithLock<T> *prev = this->_head; | |
| prev->lock_node(); | |
| NodeListWithLock<T> *curr = prev->_next; | |
| while (curr != nullptr && | |
| curr->data() < elem) { | |
| curr->lock_node(); | |
| prev->unlock_node(); | |
| prev = curr; | |
| curr = curr->_next; | |
| } | |
| if (curr == nullptr || curr->data() != elem) { | |
| prev->unlock_node(); | |
| return false; | |
| } else { | |
| prev->unlock_node(); | |
| return true; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment