forked from sinagarajan/Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbtappln.cpp
More file actions
125 lines (122 loc) · 4.97 KB
/
btappln.cpp
File metadata and controls
125 lines (122 loc) · 4.97 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
112
113
114
115
116
117
118
119
120
121
122
123
124
#include "binarytree.h"
int main()
{
int i,input,input1,*array;
struct tree *itr,*root=createNode(10);
//printf("%d",root->data);
while(1)
{
cout<<"\nEnter the option \n1 Insert into Binary Search tree"<<
"\n2 Print Inorder Recursively"<<
"\n3 Print Postorder Recursively"<<
"\n4 Print Preorder Recursively"<<
"\n5 Print Level Order"<<
"\n6 Insert into Binary tree"<<
"\n7 Count the nodes"<<
"\n8 Find Maximum and Minimum"<<
"\n9 Is BST"<<
"\n10 Print in Reverse Order"<<
"\n11 Print in ZigZag manner using One Queue"<<
"\n12 Print in ZigZag manner using 2 Stacks"<<
"\n13 Maximum height of the tree"<<
"\n14 LCA"<<
"\n15 Print All paths"<<
"\n16 Print ancestors"<<
"\n17 Find Diamter of the tree"<<
"\n18 Convert sorted array to BST"<<
"\n19 Find Max BST"<<
"\n20 Find Nodes in Circumference"<<
"\n50 Exit\n";
scanf("%d",&i);
switch (i)
{
case 1:
printf("\nEnter the value \n");scanf("%d",&input);
insertNodeBST(root,input);
break;
case 2:
printInorderRecursive(root);
break;
case 3:
printPostorderRecursive(root);
break;
case 4:
printPreorderRecursive(root);
break;
case 5:
printLevelorder(root);
break;
case 6:
printf("\nEnter the value \n");scanf("%d",&input);
insertNodeBT(root,input);
break;
case 7:
input=countNode(root);
printf("\nNumber of nodes %d",input);
break;
case 8:
printf("Maximum value is %d",findMaxBT(root));
printf("\nMinimum value is %d",findMinBT(root));
break;
case 9:
if(findIsBST(root))
printf("\nIt's BST");
else
printf("\nIt's not a BST");
if(findIsBST1(root,0,32767))
printf("\nIt's BST");
else
printf("\nIt's not a BST");
break;
case 10:
printReverse(root);
break;
case 11:
printZigZag(root);
break;
case 12:
printZigZagStack(root);
break;
case 13:
input=printMaxHeight(root);
printf("\nHeight of the tree is %d",input);
break;
case 14:
printf("\nEnter the value \n");scanf("%d",&input);
printf("\nEnter the value \n");scanf("%d",&input1);
itr=findLCA(root,input,input1);
if(itr)
{printf("\nLCA is %d",itr->data);}
break;
case 15:
printAllPaths(root);
break;
case 16:
printf("\nEnter the value \n");scanf("%d",&input);
printAncestors(root,input);
break;
case 17:
printf("\nDiameter of the tree is %d",findDiameter(root));
break;
case 18:
printf("\nEnter the size of the array\n");scanf("%d",&input);array=new int[input];
for(i=0;i<input;i++)
scanf("%d",&array[i]);
itr=convertSortedArraytoBST(array,0,input-1);
printLevelorder(itr);
break;
case 19:
// itr=findLargestBSTSubtree(root);
// printLevelorder(itr);
cout<<"not implemented yet\n";
break;
case 20:
findCircumference(root);
break;
case 50:
exit(1);
default:
printf("Provide correct option\n");
}
}
}