-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbinarytree.c
54 lines (46 loc) · 1.15 KB
/
binarytree.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdio.h>
#include <stdlib.h>
struct Node {
int broj;
struct Node *left;
struct Node *right;
} *parent = NULL;
void ubaciBroj(struct Node **node, int broj) {
//printf("Ubacujem broj");
if ((*node) == NULL) {
(*node) = (struct Node*) malloc( sizeof( struct Node ) );
(*node)->left = NULL;
(*node)->right = NULL;
(*node)->broj = broj;
} else if (broj > (*node)->broj) {
ubaciBroj(&(*node)->right, broj);
} else if (broj < (*node)->broj) {
ubaciBroj(&(*node)->left, broj);
} else {
//no - op
return;
}
}
void pronadjiElement(struct Node **node, int broj) {
// za domaci
}
void stampaj(struct Node *p) {
if (p != NULL) {
//za domaci, nacrtati kojim redosledom se stampaju ovi elementi ako printf stoji ovde
stampaj(p->left);
// ako printf stoji ovde
stampaj(p->right);
printf("%d, ", p->broj);
//ako printf stoji ovde
}
}
int main() {
ubaciBroj(&parent, 34);
ubaciBroj(&parent, 37);
ubaciBroj(&parent, 134);
ubaciBroj(&parent, 23);
ubaciBroj(&parent, 11);
ubaciBroj(&parent, 116);
stampaj(parent);
printf("\n");
}