summaryrefslogtreecommitdiff
path: root/tree/src/main.cpp
blob: b5db0c5f572b16888f04bf762e0b8426f564c823 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
 * main.cpp
 *
 *  Created on: Jan 25, 2017
 *      Author: jonas
 */

#include <iostream>
#include <string>
#include <sstream>
#include "cTree.h"

using namespace std;

cTree* a;

void fill(void);

void stress(void);

int main (void)
{
	a = new cTree();
	int i; //Argument Integer
	int iInputOption; //Input Selection
	string s; //Argument String

	cout << endl;
	cout << "| |" << endl;
	cout << "| |_ _ __ ___  ___ " << endl;
	cout << "| __| '__/ _ \\/ _ \\" << endl;
	cout << "| |_| | |  __/  __/" << endl;
	cout << " \\__|_|  \\___|\\___|" << endl << endl;


	while (1)
	{
		cout << "===========================\n";
		cout << "[1] Fill with Data\n";
		cout << "[2] Clear\n";
		cout << "[3] Balance\n";
		cout << "[4] Draw\n";
		cout << "[5] Info\n";
		cout << "[6] Insert\n";
		cout << "[7] Remove\n";
		cout << "[8] Get by Inorder ID\n";
		cout << "[9] Stresstest\n";
		cout << "[0] Exit\n";
		cout << "> ";

		cin >> iInputOption;

		switch(iInputOption)
		{
		case 0: //fill
			return 0;
			break;
		case 1: //fill
			cout << "Filling with Data.....";
			fill();
			cout << "OK\n";
			break;
		case 2: //clear
			a->clear();
			break;
		case 3: //balance
			a->sort();
			break;
		case 4: //draw
			a->draw();
			break;
		case 5: //Info
			cout << "Size: " << a->size() << ", Depth: " << a->depth() << ", Unbalance: " << a->gradeOfUnbalance() << endl << endl;
			break;
		case 6: //Insert
			cout << "Insert: ";
			cin >> s;
			a->insert(s);
			break;
		case 7: //Remove
			cout << "ID to remove: ";
			cin >> i;
			a->remove((*a)[i]);
			break;
		case 8: //get by ID
			cout << "ID to get: ";
			cin >> i;
			cout << i << ": " << (*a)[i]->getData() << endl;
			break;
		case 9:
			cout << "Started Stress-Loop. Stop with Ctrl+C\n";
			stress();
			break;
		default:
			cout << "Unrecognized Command\n";
			break;
		}
	}
	delete a;

	return 0;
}

void fill(void)
{
	for (char b = ' '; b <= '~'; b++) //insert some data into tree
	{
		for(char c = ' '; c<= '~'; c++)
		{
			stringstream ss;
			ss << b;
			ss << c;

			a->insert(ss.str());
		}
	}
}


void stress(void)
{
	while(1)
	{
		fill();
		a->sort();
		for(unsigned int i = 0; i < a->size(); i++)
		{
			a->remove((*a)[i]);
		}
	}
}