Skip to content

Commit a80f984

Browse files
committed
🔨 refactor: minor change in layout, change delay
1 parent 62e80bf commit a80f984

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

tree_visualization.c

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,46 @@ void printTree(int x, int y, int* array,int index,int total_elements)
1111
char str[10];
1212
//Base case of our recursive function
1313
if (index >= total_elements)
14-
return;
14+
return;
1515

1616
// Convert int value into string
1717
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
2323
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+
2728
// Print the values of the node
2829
// in the circle
2930
outtextxy(x - 2, y - 3, str);
30-
delay(100);
31+
delay(200);
3132
// Set the color of the line
32-
// from parent to child as green
33-
setcolor(GREEN);
33+
setcolor(RED);
3434
// Evaluating left and right child
3535
left = 2 * index + 1;
3636
right = 2 * index + 2;
3737
// Recursively draw the left subtree
3838
// and the right subtree
3939
printTree(x - y / (index + 1), y + 50,array, left, total_elements);
4040
printTree(x + y / (index + 1), y + 50,array, right, total_elements);
41+
4142
// Draw the line (or link) when the
4243
// node is not the leaf node
4344
if (left < total_elements)
4445
{
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);
4748
}
4849
if (right < total_elements)
4950
{
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);
5253
}
53-
return ;
5454
}
5555

5656
int main()
@@ -63,10 +63,11 @@ int main()
6363
array=(int*)malloc(sizeof(int)*size);
6464
for(i=0;i<size;++i)
6565
{
66-
printf("Enter node %d: ",i+1);
67-
scanf("%d",(array+i));
66+
printf("Enter node %d: ",i+1);
67+
scanf("%d",(array+i));
6868
}
6969
clrscr();
70+
setbkcolor(BLACK);
7071
printTree(300, 100, array, 0, size);
7172
getch();
7273
closegraph();

0 commit comments

Comments
 (0)