-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.c
45 lines (40 loc) · 1004 Bytes
/
test.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
#include "bst.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
node_t *root = NULL;
int debug = 0;
char c = '0';
int k = 0;
printf("> ");
while (scanf("%c", &c) == 1 && c != 'q') {
if (c == 'a') {
scanf("%d", &k);
root = insert(root, k, "empty");
if (debug) {
print_tree(root);
}
} else if (c == 's') {
scanf("%d", &k);
node_t *n = search(root, k);
if (n)
printf("%ld data=\"%s\"\n", n->key, n->data);
} else if (c == 'r') {
scanf("%d", &k);
root = remove_item(root, k);
if (debug) {
print_tree(root);
}
} else if (c == 'd') {
debug = 1 - debug;
} else if (c == 'p') {
print_tree(root);
}
if (c == '\n') {
printf("> ");
}
}
free_tree(root);
return 0;
}