-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTreesUsingArray.c
74 lines (68 loc) · 1.22 KB
/
TreesUsingArray.c
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
#include<stdio.h>
#include<stdlib.h>
int a[100]={0};
int count=0;
void insert()
{
printf("Enter number: ");
int in;
scanf("%d",&in);
a[count++]=in;
}
void del()
{
int num;
scanf("%d",&num);
for(int i=0; i<count; i++)
{
if(a[i]==num)
{
count--;
a[i]=a[count];
a[count]=0;
break;
}
}
}
void search()
{
int num,flag=0;
printf("Enter number to be searched: ");
scanf("%d",&num);
for(int i=0; i<count; i++)
if(a[i]==num)
flag=1;
if(flag)
printf("Foiund");
else
printf("Not found");
}
void inorder(int x)
{
int i,j;
i=2*x+1;
if(a[i]!=0)
traverse(i);
printf("%d",a[x]);
j=2*x+2;
if(a[j]!=0)
traverse(j);
}
int main()
{
int in;
do
{
system("cls");
printf("1.Insert element\n2.Delete element\n3.Search element\n4.Traverse tree\n");
scanf("%d",&in);
switch(in)
{
case 1: insert(); break;
case 2: del(); break;
case 3: search();break;
case 4: inorder(0); getch(); break;
}
}while(in!=-1);
return 0;
}