Mercurial > hg > Members > menikon > CbC_xv6
annotate src/SingleLinkedStack.cbc @ 122:f6558602f31e
tweak
author | anatofuz |
---|---|
date | Mon, 02 Dec 2019 19:21:20 +0900 |
parents | 822d74c14f38 |
children |
rev | line source |
---|---|
80 | 1 #include "../context.h" |
2 #interface "Stack.h" | |
3 | |
82 | 4 Stack* createSingleLinkedStack(struct Context* cbc_context) { |
80 | 5 struct Stack* stack = new Stack(); |
6 struct SingleLinkedStack* singleLinkedStack = new SingleLinkedStack(); | |
7 stack->stack = (union Data*)singleLinkedStack; | |
8 singleLinkedStack->top = NULL; | |
9 stack->push = C_pushSingleLinkedStack; | |
10 stack->pop = C_popSingleLinkedStack; | |
11 stack->pop2 = C_pop2SingleLinkedStack; | |
12 stack->get = C_getSingleLinkedStack; | |
13 stack->get2 = C_get2SingleLinkedStack; | |
14 stack->isEmpty = C_isEmptySingleLinkedStack; | |
15 stack->clear = C_clearSingleLinkedStack; | |
16 return stack; | |
17 } | |
18 | |
118
822d74c14f38
comment in SingleLinkedStack
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
82
diff
changeset
|
19 /* |
80 | 20 void printStack1(union Data* data) { |
21 struct Node* node = &data->Element.data->Node; | |
22 // if (node == NULL) { | |
23 // printf("NULL"); | |
24 // } else { | |
25 // printf("key = %d ,", node->key); | |
26 // printStack1((union Data*)data->Element.next); | |
27 // } | |
28 } | |
29 | |
30 void printStack(union Data* data) { | |
31 printStack1(data); | |
32 // printf("\n"); | |
33 } | |
118
822d74c14f38
comment in SingleLinkedStack
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
82
diff
changeset
|
34 */ |
80 | 35 |
36 __code clearSingleLinkedStack(struct SingleLinkedStack* stack,__code next(...)) { | |
37 stack->top = NULL; | |
38 goto next(...); | |
39 } | |
40 | |
41 __code pushSingleLinkedStack(struct SingleLinkedStack* stack, union Data* data, __code next(...)) { | |
42 Element* element = new Element(); | |
43 element->next = stack->top; | |
44 element->data = data; | |
45 stack->top = element; | |
46 goto next(...); | |
47 } | |
48 | |
49 __code popSingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, ...)) { | |
50 if (stack->top) { | |
51 data = stack->top->data; | |
52 stack->top = stack->top->next; | |
53 } else { | |
54 data = NULL; | |
55 } | |
56 goto next(data, ...); | |
57 } | |
58 | |
59 __code pop2SingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, union Data* data1, ...)) { | |
60 if (stack->top) { | |
61 data = stack->top->data; | |
62 stack->top = stack->top->next; | |
63 } else { | |
64 data = NULL; | |
65 } | |
66 if (stack->top) { | |
67 data1 = stack->top->data; | |
68 stack->top = stack->top->next; | |
69 } else { | |
70 data1 = NULL; | |
71 } | |
72 goto next(data, data1, ...); | |
73 } | |
74 | |
75 | |
76 __code getSingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, ...)) { | |
77 if (stack->top) | |
78 data = stack->top->data; | |
79 else | |
80 data = NULL; | |
81 goto next(data, ...); | |
82 } | |
83 | |
84 __code get2SingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, union Data* data1, ...)) { | |
85 if (stack->top) { | |
86 data = stack->top->data; | |
87 if (stack->top->next) { | |
88 data1 = stack->top->next->data; | |
89 } else { | |
90 data1 = NULL; | |
91 } | |
92 } else { | |
93 data = NULL; | |
94 data1 = NULL; | |
95 } | |
96 goto next(data, data1, ...); | |
97 } | |
98 | |
99 __code isEmptySingleLinkedStack(struct SingleLinkedStack* stack, __code next(...), __code whenEmpty(...)) { | |
100 if (stack->top) { | |
101 goto next(...); | |
102 } else { | |
103 goto whenEmpty(...); | |
104 } | |
105 } | |
106 | |
107 |