summaryrefslogtreecommitdiff
path: root/tree/src/main.cpp
blob: 8a90e8eaa6af46f23d759191f50c4fb807c0b460 (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
/*
 * 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);

int main (void)
{
	a = new cTree();
	int i;
	int iInputOption;
	string s;

	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 << "[0] Exit\n";
		cout << "> ";

		cin >> iInputOption;

		switch(iInputOption)
		{
		case 0:
			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;
		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());
		}
	}
}