From 5932ab4af9c50303e4c5683002cff6ff74133a1f Mon Sep 17 00:00:00 2001 From: Hannes Kuchelmeister Date: Wed, 30 Dec 2020 16:26:16 +0100 Subject: [PATCH] add implementation for remove to fine grained_list --- Assignment_2/FineList.cpp | 43 +++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/Assignment_2/FineList.cpp b/Assignment_2/FineList.cpp index e3bb480..cc6b41e 100644 --- a/Assignment_2/FineList.cpp +++ b/Assignment_2/FineList.cpp @@ -55,20 +55,41 @@ bool Set::add(int element) { c->unlock(); p->unlock(); return false; - } - } - - Node* n = new Node(); - n->data = element; - n->next = c; - p->next = n; - - c->unlock(); - p->unlock(); - return true; + } } + Node* n = new Node(); + n->data = element; + n->next = c; + p->next = n; + + c->unlock(); + p->unlock(); + return true; +} + bool Set::rmv(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) { + p->next = c->next; + + c->unlock(); + p->unlock(); + return true; + } + + } + + c->unlock(); + p->unlock(); return false; } bool Set::ctn(int element) {