summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar jonas <himself@jonasgunz.de> 2017-02-09 13:40:48 +0100
committerGravatar jonas <himself@jonasgunz.de> 2017-02-09 13:40:48 +0100
commit0099c4f3120dbce9315a6c1dfdd8f3cf827e1e9a (patch)
treeeb02bf33d3fa5e0f3b2b1fb19ae1fa54ee0f8778
parent78da000aa98900987d559eac1d6193cf0430ecc9 (diff)
downloadtree-0099c4f3120dbce9315a6c1dfdd8f3cf827e1e9a.tar.gz
Now able to add Lists
+cTree::insertList() adds sortet List optimized to tree
-rw-r--r--tree/.settings/language.settings.xml4
-rw-r--r--tree/src/cNode.cpp2
-rw-r--r--tree/src/cNode.h2
-rw-r--r--tree/src/cTree.cpp34
-rw-r--r--tree/src/cTree.h1
-rw-r--r--tree/src/main.cpp32
6 files changed, 61 insertions, 14 deletions
diff --git a/tree/.settings/language.settings.xml b/tree/.settings/language.settings.xml
index e4c49b3..0d521f3 100644
--- a/tree/.settings/language.settings.xml
+++ b/tree/.settings/language.settings.xml
@@ -5,7 +5,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
- <provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="903670054141926848" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+ <provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="903827296288134848" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
@@ -16,7 +16,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
- <provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="903670054141926848" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+ <provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="903827296288134848" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
diff --git a/tree/src/cNode.cpp b/tree/src/cNode.cpp
index 60974f4..beec425 100644
--- a/tree/src/cNode.cpp
+++ b/tree/src/cNode.cpp
@@ -23,8 +23,6 @@ cDatanode::cDatanode(cData* _data)
cDatanode::~cDatanode()
{
delete data;
- ///TODO FIX this shit -> remove()?
-
delete nextSmaller;
delete nextBigger;
}//Destructor
diff --git a/tree/src/cNode.h b/tree/src/cNode.h
index 1c81aaf..3ee46e2 100644
--- a/tree/src/cNode.h
+++ b/tree/src/cNode.h
@@ -43,7 +43,7 @@ public:
*/
virtual void getSortet(list<cData>* _list) = 0;
/*
- * TODO Fix memory exception. -> remove()?
+ * gets sortet list
*/
virtual void clear() = 0;
diff --git a/tree/src/cTree.cpp b/tree/src/cTree.cpp
index d2e2965..c342f34 100644
--- a/tree/src/cTree.cpp
+++ b/tree/src/cTree.cpp
@@ -58,12 +58,42 @@ cData* cTree::search(string _search)
void cTree::clear()
{
- //root->clear();
- cout << "clearTree\n";
delete root;
root = new cEndnode();
}
+void cTree::insertList(list<cData>* _list)
+{
+ unsigned int oldSize= _list->size();
+ list<cData> tmpList;
+
+ if (oldSize <= 0)
+ return;
+
+ for (unsigned int i = 0; i < oldSize / 2; i++)
+ {
+ tmpList.push_back(_list->front());
+ _list->pop_front();
+ }
+
+ insert(_list->front().clone());
+ _list->pop_front();
+ insertList(&tmpList);
+
+ tmpList.clear();
+
+ if(_list->size() <= 0)
+ return;
+
+ oldSize = _list->size();
+ for (unsigned int i = 0; i < oldSize; i++)
+ {
+ tmpList.push_back(_list->front());
+ _list->pop_front();
+ }
+ insertList(&tmpList);
+}
+
diff --git a/tree/src/cTree.h b/tree/src/cTree.h
index b18c5c3..40fda77 100644
--- a/tree/src/cTree.h
+++ b/tree/src/cTree.h
@@ -20,6 +20,7 @@ public:
~cTree();
void insert(cData*);
void insert(string);
+ void insertList(list<cData>*);
void balance();
void getList(list<cData>*);
void remove(cData*);
diff --git a/tree/src/main.cpp b/tree/src/main.cpp
index 0635602..1fe9fc3 100644
--- a/tree/src/main.cpp
+++ b/tree/src/main.cpp
@@ -11,23 +11,41 @@
int main (void)
{
cTree* a = new cTree();
- a->insert("Hallo");
- a->insert("servus");
- a->insert("moinmoin");
+ a->insert("z");
+ a->insert("f");
+ a->insert("a");
+ a->insert("n");
+ a->insert("p");
+ a->insert("k");
a->draw();
cout << "-------------------" << endl;
- a->remove(a->search("Hallo"));
- a->draw();
- cout << "clear\n";
+ list<cData> list, list2;
+ a->getList(&list);
+
+ list2 = list;
+
+ unsigned int asdf = list2.size();
+
+ for(unsigned int i = 0; i < asdf;i++)
+ {
+ cout << list2.front().getData() << ", ";
+ list2.pop_front();
+ }
+ cout << endl;
+
a->clear();
+ a->insertList(&list);
+ a->draw();
+ delete a;
/*while(1)
{
a->insert("h");
a->insert("y");
a->insert("k");
- a->insert("h");
+ a->insert("z");
a->remove(a->search("h"));
+ a->remove(a->search("k"));
a->clear();
}*/