-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree.cpp
More file actions
88 lines (84 loc) · 2.12 KB
/
tree.cpp
File metadata and controls
88 lines (84 loc) · 2.12 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
#include <iostream>
#include "teacher.h"
#include "person.h"
#include "binary_tree_node.h"
#include "binary_tree.h"
using namespace std;
int main()
{
int i, n;
int choice;
binary_tree_node *btreenode_n;
binary_tree *btree = new binary_tree;
printf("\nINFORMATION\n");
do
{
printf(" \n 1.Tree \n 2.Search \n 3.Display inorder tree \n 4.Display preorder tree \n 5.Display postorder tree \n 6.Delete \n 7.Exit \n");
printf("\nEnter your choice \n");
scanf("%d", &choice);
switch (choice)
{
case 1:
{
printf("\nHow many students information has to be entered\n");
scanf("%d", &n);
for (i = 0; i < n; i++)
{
teacher *s = new teacher();
s->initialize();
btreenode_n = new binary_tree_node(s);
btree->insert(btreenode_n);
}
}
break;
case 2:
{
char *name;
binary_tree_node *node;
name = new char[1000];
printf("Enter the Key/Name to be Searched in Tree \n");
scanf("%s", name);
node = btree->search(name);
if (node == NULL)
{
printf("Node not found for name %s\n", name);
continue;
}
printf("Found node\n");
node->display_binary_tree_node();
}
break;
case 3:
{
btree->inorder_node();
}
break;
case 4:
{
btree->preorder_node();
}
break;
case 5:
{
btree->postorder_node();
}
break;
case 6:
{
char *name;
binary_tree_node *node;
printf("Enter the Key/Name to be Deleted in Tree \n");
scanf("%s", name);
btree->delete_node(name);
}
break;
case 7:
exit(0);
break;
default:
printf("\nEnter correct choice\n");
break;
}
} while (choice != 7);
free(btree);
}