/
main.c
103 lines (90 loc) · 2.26 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <stdlib.h>
#include <stdio.h>
#include "BinarySearchTree.h"
#ifdef WIN32
#define BTSCAN scanf_s
#else
#define BTSCAN scanf
#endif
int main(int argc, char** argv)
{
TREE pTree = AllocTree(NULL);
void *pContents;
ITERATOR pIter;
int nChoice = 0, nKey;
while (nChoice != -1)
{
printf("1: Insert\n");
printf("2: Remove\n");
printf("3: Print\n");
printf("4: Print all keys\n");
printf("5: Print all keys reverse\n");
printf("6: Mass insert\n");
printf("7: Mass remove\n");
printf("Else: Quit\n\n");
BTSCAN("%d", &nChoice);
switch(nChoice)
{
case 1:
printf("Key: ");
BTSCAN("%d", &nKey);
Insert(nKey, "temp", pTree);
break;
case 2:
printf("Key: ");
BTSCAN("%d", &nKey);
Remove(nKey, pTree);
break;
case 3:
printf("Key: " );
BTSCAN("%d", &nKey);
pContents = Search(nKey, pTree);
if (pContents != NULL)
{
printf("Contents: %s\n", pContents);
}
else
{
printf("Not found\n");
}
break;
case 4:
pIter = AllocIterator();
Attach(pIter, pTree);
while ((pContents = Next(pIter)) != NULL)
{
printf("Contents: %d\n", pContents);
}
Detach(pIter);
FreeIterator(pIter);
break;
case 5:
pIter = AllocIterator();
AttachEnd(pIter, pTree);
while ((pContents = Next(pIter)) != NULL)
{
printf("Contents: %d\n", pContents);
}
Detach(pIter);
FreeIterator(pIter);
break;
case 6:
for (nKey = 100; nKey > 0; nKey--)
{
Insert(nKey, "temp", pTree);
}
break;
case 7:
for (nKey = 100; nKey > 0; nKey--)
{
Remove(nKey, pTree);
}
break;
default:
nChoice = -1;
break;
}
printf("\n");
}
return 0;
}