-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_test.c
More file actions
52 lines (46 loc) · 837 Bytes
/
Copy pathstack_test.c
File metadata and controls
52 lines (46 loc) · 837 Bytes
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
/*
* stack_test.c
*
* Created on: May 20, 2016
* Author: Moawiya
*/
#include "Stack.h"
char* copyChar(char* c) {
char* copied = allocate(sizeof(char));
*copied = *c;
return copied;
}
void freeChar(char* c) {
if (c != NULL)
deallocate(c, sizeof(*c));
//free(c);
}
int main(void) {
initMemory();
Stack s = createStack((StackData)©Char, (freeStackData)(&freeChar));
char c = 'a';
ReturnVal ret = push(&c, s);
c = 'b';
push(&c, s);
c = 'c';
push(&c, s);
c = 'a';
push(&c,s);
if (ret == Success) {
printf("pushed\n");
}
char* ch;
ret = top(s, (void**)&ch);
printf("%d\n", stackSize(s));
if (*ch == 'a') {
printf("heeeeee\n");
}
deallocate(ch, 1);
printStack(s);
ret = pop(s);
printf("after pop\nsize: %d\n\n", stackSize(s));
printStack(s);
destroyStack(s);
finishMemory();
return 0;
}