-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_tree.cpp
More file actions
111 lines (108 loc) · 2.59 KB
/
main_tree.cpp
File metadata and controls
111 lines (108 loc) · 2.59 KB
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
#include <iostream>
#include "mavl.hpp"
#include <fstream>
using namespace std;
int main(){
MAVLTree m;
ifstream file;
file.open("entries.txt");
if( !file){
cout << "Error opening file" << endl;
return -1;
}
int roll_no;
string name;
while(file >> roll_no >> name){
m.insert(roll_no,name);
}
file.close();
char y = 'y';
while( y=='y' || y=='Y'){
int h;
cout << "Please enter 1 to insert" << endl;
cout << "Please enter 2 to delete by key" << endl;
cout << "Please enter 3 to get place of a key" << endl;
cout << "Please enter 4 to delete by place of a key" << endl;
cout << "Please enter 5 to search for a key" << endl;
cout << "Please enter 6 to find size of tree" << endl;
cout << "Please enter 7 to check if tree is empty" << endl;
cin >> h;
if( h==1){
cout << "Please enter the roll number and name of your entry" << endl;
cout << "Roll No : " ;
cin >> roll_no ;
while(cin.fail()){
cout << "PLease enter integer input" << endl;
cin.clear();
cin.ignore(256,'\n');
cin >> roll_no ;
}
cout << "Name : " ;
cin >> name;
m.insert(roll_no , name);
}
else if(h==2){
int key;
cout << "Please enter the key you want to delete : " ;
cin >> key;
while(cin.fail()){
cout << "PLease enter integer input" << endl;
cin.clear();
cin.ignore(256,'\n');
cin >> key ;
}
m.remove(key);
}
else if(h==3){
int k;
cout << "Please note that places begin from 1" << endl;
cout << "Please enter the key : " ;
cin >> k;
while(cin.fail()){
cout << "PLease enter integer input" << endl;
cin.clear();
cin.ignore(256,'\n');
cin >> k ;
}
cout << m.get_place(k) << endl;
}
else if(h==4){
int place;
cout << "Please note that places begin from 1" << endl;
cout << "Please enter the place : " ;
cin >> place;
while(cin.fail()){
cout << "PLease enter integer input" << endl;
cin.clear();
cin.ignore(256,'\n');
cin >> place ;
}
m.delete_by_place(place);
}
else if(h==5){
int se;
cout << "Please enter the key : " ;
cin >> se;
while(cin.fail()){
cout << "PLease enter integer input" << endl;
cin.clear();
cin.ignore(256,'\n');
cin >> se ;
}
cout << m.search(se) << endl;
}
else if(h==6){
cout << "Tree size= " << m.size() << endl;
}
else if(h==7){
if(m.isEmpty()) cout << "The tree is empty." << endl;
else cout << "The tree is not empty , it has " << m.size() << " nodes." << endl;
}
else{
cout << "Please enter correct input !!" << endl;
}
cout << "Would you like to continue? y/n " ;
cin >> y;
cout << endl;
}
}