summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar jonas <himself@jonasgunz.de> 2017-02-08 07:42:36 +0100
committerGravatar jonas <himself@jonasgunz.de> 2017-02-08 07:42:36 +0100
commit78da000aa98900987d559eac1d6193cf0430ecc9 (patch)
tree34fd03e02fd989e45bcb2745f4b5cdd0cdd3593d
parent04d43ddefcec872793978680542f0b9d746fab35 (diff)
downloadtree-78da000aa98900987d559eac1d6193cf0430ecc9.tar.gz
works
-rw-r--r--tree/src/cData.cpp5
-rw-r--r--tree/src/cData.h5
-rw-r--r--tree/src/cNode.cpp16
-rw-r--r--tree/src/cNode.h7
-rw-r--r--tree/src/cTree.cpp2
5 files changed, 22 insertions, 13 deletions
diff --git a/tree/src/cData.cpp b/tree/src/cData.cpp
index 1599c3f..f0919c6 100644
--- a/tree/src/cData.cpp
+++ b/tree/src/cData.cpp
@@ -63,6 +63,9 @@ bool cData::operator==(string _data)
return true;
return false;
}
-
+cData *cData::clone()
+{
+ return new cData(sData);
+}
diff --git a/tree/src/cData.h b/tree/src/cData.h
index c0c2e28..4fbfdb3 100644
--- a/tree/src/cData.h
+++ b/tree/src/cData.h
@@ -29,6 +29,11 @@ public:
* Returns content of cData instance as String
*/
+ cData* clone();
+ /*
+ * clones current cData instance
+ */
+
bool operator<(cData);
bool operator>(cData);
bool operator<(string);
diff --git a/tree/src/cNode.cpp b/tree/src/cNode.cpp
index 265a2b9..60974f4 100644
--- a/tree/src/cNode.cpp
+++ b/tree/src/cNode.cpp
@@ -22,8 +22,9 @@ cDatanode::cDatanode(cData* _data)
cDatanode::~cDatanode()
{
- cout << "DestructorNode\n";
delete data;
+ ///TODO FIX this shit -> remove()?
+
delete nextSmaller;
delete nextBigger;
}//Destructor
@@ -81,17 +82,10 @@ void cDatanode::getSortet(list<cData>* _list)
void cDatanode::clear()
{
- /*nextSmaller->clear();
- delete nextSmaller;
- nextSmaller = NULL;
-
- nextBigger->clear();
- delete nextBigger;
- nextBigger = NULL;*/
-
delete nextSmaller;
delete nextBigger;
- nextSmaller = nextBigger = NULL;
+ nextSmaller = new cEndnode();
+ nextBigger = new cEndnode();
}
void cDatanode::draw(int _depth)
@@ -113,7 +107,7 @@ cEndnode::~cEndnode() {}
bool cEndnode::isEnd()
{
- delete this; ///TODO Check if it works!!!
+ delete this;
return true;
}
diff --git a/tree/src/cNode.h b/tree/src/cNode.h
index cffc7a5..1c81aaf 100644
--- a/tree/src/cNode.h
+++ b/tree/src/cNode.h
@@ -39,10 +39,17 @@ public:
virtual bool isEnd() = 0;
/*
* returns false
+ * TODO Remove
*/
virtual void getSortet(list<cData>* _list) = 0;
+ /*
+ * TODO Fix memory exception. -> remove()?
+ */
virtual void clear() = 0;
+ /*
+ * TODO Remove
+ */
virtual void draw(int _depth) = 0;
};
diff --git a/tree/src/cTree.cpp b/tree/src/cTree.cpp
index 3ab7324..d2e2965 100644
--- a/tree/src/cTree.cpp
+++ b/tree/src/cTree.cpp
@@ -36,7 +36,7 @@ void cTree::remove(cData* _data)
///TODO: Optimize!!!
while(!dataList.empty())
{
- insert(&dataList.front());
+ insert(dataList.front().clone());
dataList.pop_front();
}
}