-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_bag.c
59 lines (47 loc) · 1.35 KB
/
test_bag.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
#include <stdio.h>
#include "bag.h"
int main()
{
printf("\n\nTesting bag data structure\n\n");
Bag* root = BagConstructor();
printf("Adding an entry at position 15 with value 42.\n");
BagAdd(root, 15, 42);
printf("Adding an entry at position 15 with value 42.\n");
BagAdd(root, 15, 42);
printf("Adding an entry at position 15 with value 42.\n");
BagAdd(root, 15, 15);
printf("Adding an entry at position 10 with value 15.\n");
BagAdd(root, 10, 15);
printf("Adding an entry at position -10 with value -10.\n");
BagAdd(root, -10, -10);
printf("Printing number of bags.\n");
Bag* iter = root;
int i = 0;
while (iter->next)
{
printf("%i", i++);
ChildBag* childIter = iter->next->value;
while (childIter)
{
printf(" - %i", childIter->value);
childIter = childIter->next;
}
printf("\n");
iter = iter->next;
}
printf("Printing number of bags using iterate.\n");
BagIterate(&iter, root);
i=0;
while (BagIterate(&iter, NULL))
{
printf("%i", i++);
ChildBag* childIter = iter->next->value;
while (childIter)
{
printf(" - %i", childIter->value);
childIter = childIter->next;
}
printf("\n");
}
return 0;
}