-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.c
39 lines (33 loc) · 811 Bytes
/
main.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
#include <stdio.h>
#include "tree.h"
static char *teams[] = {
"Pittsburgh", "Penguins",
"Washington", "Capitals",
"Philadelphia", "Flyers",
"New York", "Rangers",
"Tampa Bay", "Lightning",
"Boston", "Bruins",
"Columbus", "Blue Jackets",
};
static const int nteams = sizeof(teams) / sizeof(*teams) / 2;
void
printer(char *k, char *v)
{
printf("%-12s = %s\n", k, v);
}
int
main(void)
{
struct tree *tree = 0;
for (int i = 0; i < nteams; i++)
tree_insert(&tree, teams[i * 2 + 0], teams[i * 2 + 1]);
struct tree_it *it = tree_iterator(tree);
char *k, *v;
while (tree_next(it, &k, &v))
printf("%-12s : %s\n", k, v);
#ifdef CALLBACK_EXAMPLE
puts("---");
tree_visit(tree, printer);
#endif
tree_destroy(tree);
}