diff options
-rw-r--r-- | tree/src/cTree.cpp | 13 | ||||
-rw-r--r-- | tree/src/cTree.h | 1 | ||||
-rw-r--r-- | tree/src/main.cpp | 36 |
3 files changed, 18 insertions, 32 deletions
diff --git a/tree/src/cTree.cpp b/tree/src/cTree.cpp index c342f34..32c7179 100644 --- a/tree/src/cTree.cpp +++ b/tree/src/cTree.cpp @@ -33,12 +33,13 @@ void cTree::remove(cData* _data) list<cData> dataList; //List of Data that has to be re-inserted into the tree root->remove(_data, &dataList, &root); + insertList(&dataList); ///TODO: Optimize!!! - while(!dataList.empty()) + /*while(!dataList.empty()) { insert(dataList.front().clone()); dataList.pop_front(); - } + }*/ } void cTree::getList(list<cData>* _list) @@ -94,6 +95,14 @@ void cTree::insertList(list<cData>* _list) insertList(&tmpList); } +void cTree::sort() +{ + list<cData> sortetList; + root->getSortet(&sortetList); + clear(); + insertList(&sortetList); +} + diff --git a/tree/src/cTree.h b/tree/src/cTree.h index 40fda77..cff7dcd 100644 --- a/tree/src/cTree.h +++ b/tree/src/cTree.h @@ -24,6 +24,7 @@ public: void balance(); void getList(list<cData>*); void remove(cData*); + void sort(); void clear(); cData* search(string); diff --git a/tree/src/main.cpp b/tree/src/main.cpp index 1fe9fc3..0b9299a 100644 --- a/tree/src/main.cpp +++ b/tree/src/main.cpp @@ -11,43 +11,19 @@ int main (void) { cTree* a = new cTree(); - a->insert("z"); - a->insert("f"); - a->insert("a"); - a->insert("n"); - a->insert("p"); - a->insert("k"); - a->draw(); - cout << "-------------------" << endl; - list<cData> list, list2; - a->getList(&list); - - list2 = list; - - unsigned int asdf = list2.size(); - for(unsigned int i = 0; i < asdf;i++) + for (char i = '1'; i <= 'z'; i ++) { - cout << list2.front().getData() << ", "; - list2.pop_front(); + string s(&i); + a->insert(&s[0]); } - cout << endl; - a->clear(); - a->insertList(&list); + a->draw(); + cout << "-------------------" << endl; + a->sort(); a->draw(); delete a; - /*while(1) - { - a->insert("h"); - a->insert("y"); - a->insert("k"); - a->insert("z"); - a->remove(a->search("h")); - a->remove(a->search("k")); - a->clear(); - }*/ return 0; } |