-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.c
37 lines (33 loc) · 1.07 KB
/
util.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
//
// Created by juampa on 17/6/21.
//
#include "util.h"
char* generateSpaces(int spaces) {
char* str = calloc(spaces + 1, sizeof(char));
memset(str, ' ', spaces);
str[spaces] = '\0';
return str;
}
void printAbbFormatted(abb abb, int spaces) {
if(!abb_is_empty(abb)) {
char* strSpaces = generateSpaces(spaces);
printf("%s(+) ", strSpaces);
printf(CYAN "%d" MAGENTA RESET "\n", abb->elem);
if(!abb_is_empty(abb->left) || !abb_is_empty(abb->right)) {
// printf("\n" BLUE "%s%s's childs\n" RESET,generateSpaces(spaces), abb->key);
printf("%s- Left branch -\n", generateSpaces(spaces + 4));
printAbbFormatted(abb->left, spaces + 4);
printf("%s- Right branch -\n", generateSpaces(spaces + 4));
printAbbFormatted(abb->right, spaces + 4);
}
}
else {
printf("%s(+) Empty branch\n", generateSpaces(spaces + 4));
}
}
/*
* @toString: function takes abb->elem and returns a string representation of it
* */
void printAbb(abb abb) {
printAbbFormatted(abb, 0);
}