move if out of loop, otherwise doesn't work correctly

This commit is contained in:
2020-12-30 18:40:36 +01:00
parent 4414c55f28
commit f8666dc21b

View File

@@ -50,14 +50,13 @@ bool Set::add(int element) {
p = c; p = c;
c = c->next; c = c->next;
c->lock(); c->lock();
}
if (c->data == element) { if (c->data == element) {
c->unlock(); c->unlock();
p->unlock(); p->unlock();
return false; return false;
} } else {
}
Node* n = new Node(); Node* n = new Node();
n->data = element; n->data = element;
n->next = c; n->next = c;
@@ -66,6 +65,7 @@ bool Set::add(int element) {
c->unlock(); c->unlock();
p->unlock(); p->unlock();
return true; return true;
}
} }
bool Set::rmv(int element) { bool Set::rmv(int element) {
@@ -78,19 +78,19 @@ bool Set::rmv(int element) {
p->unlock(); p->unlock();
c = c->next; c = c->next;
c->lock(); c->lock();
}
if (c->data == element) { if (c->data == element) {
p->next = c->next; p->next = c->next;
c->unlock(); c->unlock();
p->unlock(); p->unlock();
return true; return true;
} } else {
}
c->unlock(); c->unlock();
p->unlock(); p->unlock();
return false; return false;
}
} }
bool Set::ctn(int element) { bool Set::ctn(int element) {
this->first->lock(); this->first->lock();
@@ -102,14 +102,15 @@ bool Set::ctn(int element) {
p->unlock(); p->unlock();
c = c->next; c = c->next;
c->lock(); c->lock();
}
if (c->data == element) { if (c->data == element) {
c->unlock(); c->unlock();
p->unlock(); p->unlock();
return true; return true;
} } else {
}
c->unlock(); c->unlock();
p->unlock(); p->unlock();
return false; return false;
}
} }