forked from abysamross/C_NIX_Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstacTrial.c
76 lines (54 loc) · 1.08 KB
/
stacTrial.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
#include <stdio.h>
#include "mstack.h"
struct test {
int a;
float b;
};
void func1(stack* st) {
int N = 15;
int i = 0;
int j = 0;
struct test sArr[N][N];
for (i = 0; i < N; ++i) {
for (j = 0; j < N; ++j) {
sArr[i][j].a = j;
sArr[i][j].b = j + (float)j/10.0;
}
push(st, struct test(*)[N], &sArr[i]);
}
i = 0;
while (!empty(st)) {
struct test(*s)[N] = *(struct test(**)[N])top(st);
pop(st);
printf("%d: \n", i);
for (j = 0; j < N; ++j)
printf("%d: %d, %f\n", j, (*s + j)->a, (*s + j)->b);
++i;
printf("\n");
}
printf("size: %d\n\n", size(st));
freeStack(st);
printf("\n");
}
int main(int argc, char* argv[]) {
stack* st = initStack();
int N = 10;
int i = 0;
struct test* sArr = malloc(N*sizeof(struct test));
for (i = 0; i < N; ++i) {
(sArr+i)->a = i;
(sArr+i)->b = i + (float)i/10.0;
push(st, struct test, *(sArr + i));
}
free(sArr);
i = 0;
while (!empty(st)) {
struct test t = *(struct test* )top(st);
printf("%d. %d, %f\n", i, t.a, t.b);
pop(st);
++i;
}
printf("size: %d\n\n", size(st));
func1(st);
return 0;
}