mirror of
https://github.com/13hannes11/UU_la_parallel_programming_practical_assignments.git
synced 2024-09-04 00:50:58 +02:00
improved FineList
This commit is contained in:
@@ -58,7 +58,7 @@ bool FineSet::rmv(int element) {
|
||||
c->lock();
|
||||
}
|
||||
|
||||
if (c->data == element) {
|
||||
if (c->is_equal(element)) {
|
||||
p->next = c->next;
|
||||
|
||||
c->unlock();
|
||||
|
||||
@@ -1,22 +1,29 @@
|
||||
#include <mutex>
|
||||
|
||||
class Node {
|
||||
public:
|
||||
protected:
|
||||
int data;
|
||||
bool is_dummy;
|
||||
Node* next;
|
||||
std::mutex mut;
|
||||
|
||||
public:
|
||||
Node* next;
|
||||
|
||||
Node(int element);
|
||||
static Node* Dummy();
|
||||
// Dummy();
|
||||
|
||||
void lock();
|
||||
void unlock();
|
||||
bool is_smaller_than(int n);
|
||||
bool is_smaller_than(Node* n);
|
||||
bool is_equal(int n);
|
||||
};
|
||||
|
||||
|
||||
Node::Node(int element){
|
||||
this->data = element;
|
||||
this->is_dummy = false;
|
||||
data = element;
|
||||
is_dummy = false;
|
||||
}
|
||||
|
||||
Node* Node::Dummy(){
|
||||
@@ -25,6 +32,10 @@ Node* Node::Dummy(){
|
||||
return n;
|
||||
}
|
||||
|
||||
bool Node::is_smaller_than(Node* n) {
|
||||
return this->is_smaller_than(n->data);
|
||||
}
|
||||
|
||||
bool Node::is_smaller_than(int n) {
|
||||
// Everything is smaller than a dummy -> false
|
||||
return this->data < n && !this->is_dummy;
|
||||
|
||||
Reference in New Issue
Block a user