@@ -11,46 +11,46 @@ void printTree(int x, int y, int* array,int index,int total_elements)
11
11
char str [10 ];
12
12
//Base case of our recursive function
13
13
if (index >= total_elements )
14
- return ;
14
+ return ;
15
15
16
16
// Convert int value into string
17
17
itoa (array [index ],str ,10 );
18
- // Set color of the boundary of
19
- // circle as green
20
- setcolor (GREEN );
21
- // Draw the circle of radius 15
22
- // that represent node of Tree
18
+
19
+ // Set color of the boundary of circle
20
+ setcolor (BLACK );
21
+
22
+ // Draw the circle of radius 15 that represent node of Tree
23
23
circle (x , y , 15 );
24
- delay (100 );
25
- floodfill (x , y , GREEN );
26
- delay (100 );
24
+ delay (200 );
25
+ floodfill (x , y , RED );
26
+ delay (200 );
27
+
27
28
// Print the values of the node
28
29
// in the circle
29
30
outtextxy (x - 2 , y - 3 , str );
30
- delay (100 );
31
+ delay (200 );
31
32
// Set the color of the line
32
- // from parent to child as green
33
- setcolor (GREEN );
33
+ setcolor (RED );
34
34
// Evaluating left and right child
35
35
left = 2 * index + 1 ;
36
36
right = 2 * index + 2 ;
37
37
// Recursively draw the left subtree
38
38
// and the right subtree
39
39
printTree (x - y / (index + 1 ), y + 50 ,array , left , total_elements );
40
40
printTree (x + y / (index + 1 ), y + 50 ,array , right , total_elements );
41
+
41
42
// Draw the line (or link) when the
42
43
// node is not the leaf node
43
44
if (left < total_elements )
44
45
{
45
- delay (100 );
46
- line (x , y , x - y / (index + 1 ), y + 50 );
46
+ delay (200 );
47
+ line (x , y + 14 , x - y / (index + 1 ), y + 50 - 14 );
47
48
}
48
49
if (right < total_elements )
49
50
{
50
- delay (100 );
51
- line (x , y , x + y / (index + 1 ), y + 50 );
51
+ delay (200 );
52
+ line (x , y + 14 , x + y / (index + 1 ), y + 50 - 14 );
52
53
}
53
- return ;
54
54
}
55
55
56
56
int main ()
@@ -63,10 +63,11 @@ int main()
63
63
array = (int * )malloc (sizeof (int )* size );
64
64
for (i = 0 ;i < size ;++ i )
65
65
{
66
- printf ("Enter node %d: " ,i + 1 );
67
- scanf ("%d" ,(array + i ));
66
+ printf ("Enter node %d: " ,i + 1 );
67
+ scanf ("%d" ,(array + i ));
68
68
}
69
69
clrscr ();
70
+ setbkcolor (BLACK );
70
71
printTree (300 , 100 , array , 0 , size );
71
72
getch ();
72
73
closegraph ();
0 commit comments