mirror of
https://github.com/13hannes11/UU_la_parallel_programming_practical_assignments.git
synced 2024-09-04 00:50:58 +02:00
add possibility to print a set to a string
This commit is contained in:
@@ -3,13 +3,13 @@
|
|||||||
|
|
||||||
Node::Node(int element){
|
Node::Node(int element){
|
||||||
data = element;
|
data = element;
|
||||||
is_dummy = false;
|
dummy = false;
|
||||||
deleted = false;
|
deleted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Node* Node::Dummy(){
|
Node* Node::Dummy(){
|
||||||
Node* n = new Node(0);
|
Node* n = new Node(0);
|
||||||
n->is_dummy = true;
|
n->dummy = true;
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,12 +19,12 @@ bool Node::is_smaller_than(Node* n) {
|
|||||||
|
|
||||||
bool Node::is_smaller_than(int n) {
|
bool Node::is_smaller_than(int n) {
|
||||||
// Everything is smaller than a dummy -> false
|
// Everything is smaller than a dummy -> false
|
||||||
return this->data < n && !this->is_dummy;
|
return this->data < n && !this->dummy;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Node::is_equal(int n) {
|
bool Node::is_equal(int n) {
|
||||||
// Dummies are not equal to any number -> false
|
// Dummies are not equal to any number -> false
|
||||||
return this->data == n && !this->is_dummy;
|
return this->data == n && !this->dummy;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::lock() {
|
void Node::lock() {
|
||||||
@@ -32,4 +32,12 @@ void Node::lock() {
|
|||||||
}
|
}
|
||||||
void Node::unlock() {
|
void Node::unlock() {
|
||||||
this->mut.unlock();
|
this->mut.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Node::is_dummy() {
|
||||||
|
return dummy;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Node::get_data(){
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
class Node {
|
class Node {
|
||||||
protected:
|
protected:
|
||||||
int data;
|
int data;
|
||||||
bool is_dummy;
|
bool dummy;
|
||||||
std::mutex mut;
|
std::mutex mut;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -21,4 +21,6 @@ class Node {
|
|||||||
bool is_smaller_than(int n);
|
bool is_smaller_than(int n);
|
||||||
bool is_smaller_than(Node* n);
|
bool is_smaller_than(Node* n);
|
||||||
bool is_equal(int n);
|
bool is_equal(int n);
|
||||||
|
bool is_dummy();
|
||||||
|
int get_data();
|
||||||
};
|
};
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
#include "Set.h"
|
#include "Set.h"
|
||||||
#include "Node.h"
|
#include "Node.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include<sstream>
|
||||||
|
|
||||||
Set::Set(std::string _name){
|
Set::Set(std::string _name){
|
||||||
name = _name;
|
name = _name;
|
||||||
first = Node::Dummy();
|
first = Node::Dummy();
|
||||||
@@ -11,3 +14,13 @@ bool Set::add(int element) { return false; }
|
|||||||
bool Set::rmv(int element) { return false; }
|
bool Set::rmv(int element) { return false; }
|
||||||
bool Set::ctn(int element) { return false; }
|
bool Set::ctn(int element) { return false; }
|
||||||
std::string Set::get_name() { return name; }
|
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();
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,4 +12,5 @@ class Set {
|
|||||||
bool rmv(int element);
|
bool rmv(int element);
|
||||||
bool ctn(int element);
|
bool ctn(int element);
|
||||||
std::string get_name();
|
std::string get_name();
|
||||||
|
std::string print_set();
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user