-
Notifications
You must be signed in to change notification settings - Fork 0
/
Source.c
101 lines (75 loc) · 1.97 KB
/
Source.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
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "List.h"
#include "Stack.h"
#include "Queue.h"
#define _CRT_SECURE_NO_WARNINGS 1
#define MAX_LEN 100
#define BYTE char
void ShowBits(BYTE a)
{
for (int i = 0; i < 8; ++i)
{
if (a & 0x01)
printf("1");
else
printf("0");
a = a >> 1;
}
printf("\n");
}
main(void)
{
int elems[] = { 0, 1, 2, 3, 4, 5 };
List * list = list_create();
list_add_head(list, &elems[0]);
assert(*(int*)list_get_head_data(list) == 0);
assert(*(int*)list_get_tail_data(list) == 0);
list_add_head(list, &elems[1]);
assert(*(int*)list_get_head_data(list) == 1);
assert(*(int*)list_get_tail_data(list) == 0);
list_add_head(list, &elems[2]);
assert(*(int*)list_get_head_data(list) == 2);
assert(*(int*)list_get_tail_data(list) == 0);
list_remove_head(list);
assert(*(int*)list_get_head_data(list) == 1);
assert(*(int*)list_get_tail_data(list) == 0);
list_remove_head(list);
assert(*(int*)list_get_head_data(list) == 0);
assert(*(int*)list_get_tail_data(list) == 0);
list_remove_head(list);
assert(list_get_head_data(list) == NULL);
assert(list_get_tail_data(list) == NULL);
list_add_tail(list, &elems[0]);
assert(*(int*)list_get_head_data(list) == 0);
assert(*(int*)list_get_tail_data(list) == 0);
list_add_tail(list, &elems[1]);
assert(*(int*)list_get_head_data(list) == 0);
assert(*(int*)list_get_tail_data(list) == 1);
list_add_tail(list, &elems[2]);
assert(*(int*)list_get_head_data(list) == 0);
assert(*(int*)list_get_tail_data(list) == 2);
list_destroy(list);
char str[] = "I love programming";
size_t len = strlen(str);
void * data;
Stack * st = stack_create();
for (size_t i = 0; i < len; ++i)
{
stack_push(st, &str[i]);
}
while (data = stack_pop(st))
putchar(*(char*)data);
stack_destroy(st);
putchar('\n');
Que * q = que_create();
for (size_t i = 0; i < len; ++i)
{
que_push(q, &str[i]);
}
while (data = que_pop(q))
putchar(*(char*)data);
que_destroy(q);
putchar('\n');
}