aboutsummaryrefslogtreecommitdiff
path: root/src/1-1-binary-search-tree.c
blob: cb5efc13ee1d18245c3b050105fc52f852eb2f4f (plain)
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
#include <stdbool.h>
#include <stdio.h>
#include <algolib.c>
#include <vectorlib.c>
#include <time.h>

typedef struct TREE{
    BS_Node *root;
} TREE;

int main(int argc, char **argv){
    srand(time(NULL));
    TREE tree = {NULL};

    for(int i=0; i <40; i++){
        BSAddValue(&tree.root,(int)RandomFloat(0,100));
    }

    BSPrintTree(&tree.root);
    BS_Node *found_node = BSSearchTree(&tree.root,53);
    if(found_node != NULL) {
        printf("53 found %d\n",found_node->value);
    } else {
        printf("53 not found\n");
    }
    BSFreeTree(&tree.root);
    return 0;
}

/* Challanges
 *
 * balance the tree
 */