From 4414c55f2894a47fa8386de5f516f26bfbf5a58c Mon Sep 17 00:00:00 2001 From: Hannes Kuchelmeister Date: Wed, 30 Dec 2020 16:31:55 +0100 Subject: [PATCH] implemented contains function --- Assignment_2/FineList.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Assignment_2/FineList.cpp b/Assignment_2/FineList.cpp index cc6b41e..3d009db 100644 --- a/Assignment_2/FineList.cpp +++ b/Assignment_2/FineList.cpp @@ -93,5 +93,23 @@ bool Set::rmv(int element) { return false; } bool Set::ctn(int element) { + this->first->lock(); + Node* p = this->first; + Node* c = p->next; + c->lock(); + + while (c->data < element) { + p->unlock(); + c = c->next; + c->lock(); + if (c->data == element) { + c->unlock(); + p->unlock(); + return true; + } + } + + c->unlock(); + p->unlock(); return false; } \ No newline at end of file