setup project for assignment 3

This commit is contained in:
2021-01-08 16:01:54 +01:00
parent 51b54f68fb
commit 2f9f32e50e
13 changed files with 268 additions and 0 deletions

View File

@@ -0,0 +1 @@
add_library(sets STATIC Node.h Node.cpp Set.h Set.cpp )

43
Assignment_3/lib/Node.cpp Normal file
View File

@@ -0,0 +1,43 @@
#include <mutex>
#include <lib/Node.h>
Node::Node(int element){
data = element;
dummy = false;
deleted = false;
}
Node* Node::Dummy(){
Node* n = new Node(0);
n->dummy = true;
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->dummy;
}
bool Node::is_equal(int n) {
// Dummies are not equal to any number -> false
return this->data == n && !this->dummy;
}
void Node::lock() {
this->mut.lock();
}
void Node::unlock() {
this->mut.unlock();
}
bool Node::is_dummy() {
return dummy;
}
int Node::get_data(){
return data;
}

26
Assignment_3/lib/Node.h Normal file
View File

@@ -0,0 +1,26 @@
#pragma once
#include <mutex>
class Node {
protected:
int data;
bool dummy;
std::mutex mut;
public:
Node* next;
bool deleted;
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);
bool is_dummy();
int get_data();
};

26
Assignment_3/lib/Set.cpp Normal file
View File

@@ -0,0 +1,26 @@
#include "Set.h"
#include "Node.h"
#include <iostream>
#include<sstream>
Set::Set(std::string _name){
name = _name;
first = Node::Dummy();
first->next = Node::Dummy();
}
bool Set::add(int element) { return false; }
bool Set::rmv(int element) { return false; }
bool Set::ctn(int element) { return false; }
std::string Set::get_name() { return name; }
std::string Set::print_set(){
Node* c = this->first->next;
std::stringstream ss;
while (!c->is_dummy()) {
ss << c->get_data() << " ";
c = c->next;
}
return ss.str();
}

16
Assignment_3/lib/Set.h Normal file
View File

@@ -0,0 +1,16 @@
#pragma once
#include "Node.h"
class Set {
protected:
std::string name;
Set(std::string _name);
Node* first;
public:
bool add(int element);
bool rmv(int element);
bool ctn(int element);
std::string get_name();
std::string print_set();
};