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

#define PROJECT_NAME "algorithms-binary search tree"

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
 */