fix segmentation fault by removing Node* in subclasses

This commit is contained in:
2021-01-02 16:35:03 +01:00
parent a2b836f592
commit c9352f0785
4 changed files with 3 additions and 7 deletions

View File

@@ -1,12 +1,9 @@
#pragma once
#include <bits/stdc++.h> #include <bits/stdc++.h>
#include"Node.h" #include"Node.h"
#include"Set.h" #include"Set.h"
class FineSet:public Set { class FineSet:public Set {
Node* first;
public: public:
FineSet(); FineSet();
bool add(int element); bool add(int element);
@@ -17,11 +14,13 @@ class FineSet:public Set {
FineSet::FineSet() : Set("FineSet") { } FineSet::FineSet() : Set("FineSet") { }
bool FineSet::add(int element) { bool FineSet::add(int element) {
this->first->lock(); first->lock();
return true;
Node* p = this->first; Node* p = this->first;
Node* c = p->next; Node* c = p->next;
c->lock(); c->lock();
while (c->is_smaller_than(element)) { while (c->is_smaller_than(element)) {
std::cout << "C: "<< c->next << std::endl;
p->unlock(); p->unlock();
p = c; p = c;
c = c->next; c = c->next;

View File

@@ -5,7 +5,6 @@
class LazySet:public Set { class LazySet:public Set {
protected: protected:
Node* first;
void locate(int element, Node* prev, Node* cur); void locate(int element, Node* prev, Node* cur);
public: public:

View File

@@ -4,7 +4,6 @@
#include"Set.h" #include"Set.h"
class MultiSet:public Set { class MultiSet:public Set {
Node* first;
public: public:
MultiSet(); MultiSet();
bool add(int element); bool add(int element);

View File

@@ -5,7 +5,6 @@
class OptimisticSet:public Set { class OptimisticSet:public Set {
protected: protected:
Node* first;
bool validate(Node* p, Node* c); bool validate(Node* p, Node* c);
public: public:
OptimisticSet(); OptimisticSet();