72
|
1 #include "../context.h"
|
|
2 #include <stdio.h>
|
|
3
|
|
4 Stack* createSingleLinkedStack(struct Context* context) {
|
|
5 struct Stack* stack = &ALLOCATE(context, Stack)->Stack;
|
|
6 struct SingleLinkedStack* single_linked_stack = &ALLOCATE(context, SingleLinkedStack)->SingleLinkedStack;
|
|
7 stack->stack = (union Data*)single_linked_stack;
|
|
8 stack->data = NULL;
|
|
9 stack->data1 = NULL;
|
|
10 single_linked_stack->top = NULL;
|
|
11 stack->clear = C_clearSingleLinkedStack;
|
|
12 stack->push = C_pushSingleLinkedStack;
|
|
13 stack->pop = C_popSingleLinkedStack;
|
|
14 stack->pop2 = C_pop2SingleLinkedStack;
|
|
15 stack->isEmpty = C_isEmptySingleLinkedStack;
|
|
16 stack->get = C_getSingleLinkedStack;
|
|
17 stack->get2 = C_get2SingleLinkedStack;
|
|
18 return stack;
|
|
19 }
|
|
20 // include "Node.h"
|
|
21
|
|
22
|
|
23 void printStack1(union Data* data) {
|
|
24 struct Node* node = &data->Element.data->Node;
|
|
25 if (node == NULL) {
|
|
26 printf("NULL");
|
|
27 } else {
|
|
28 printf("key = %d ,", node->key);
|
|
29 printStack1((union Data*)data->Element.next);
|
|
30 }
|
|
31 }
|
|
32
|
|
33 void printStack(union Data* data) {
|
|
34 printStack1(data);
|
|
35 printf("\n");
|
|
36 }
|
|
37
|
|
38 __code clearSingleLinkedStack(struct Context *context,struct SingleLinkedStack* stack,enum Code next) {
|
|
39 stack->top = NULL;
|
|
40 goto meta(context, next);
|
|
41 }
|
|
42
|
|
43 __code clearSingleLinkedStack_stub(struct Context* context) {
|
|
44 SingleLinkedStack* stack = (SingleLinkedStack*)GearImpl(context, Stack, stack);
|
|
45 enum Code next = Gearef(context, Stack)->next;
|
|
46 goto clearSingleLinkedStack(context, stack, next);
|
|
47 }
|
|
48
|
|
49 __code pushSingleLinkedStack(struct Context *context,struct SingleLinkedStack* stack, union Data* data, enum Code next) {
|
|
50 Element* element = &ALLOCATE(context, Element)->Element;
|
|
51 element->next = stack->top;
|
|
52 element->data = data;
|
|
53 stack->top = element;
|
|
54 goto meta(context, next);
|
|
55 }
|
|
56
|
|
57 __code pushSingleLinkedStack_stub(struct Context* context) {
|
|
58 SingleLinkedStack* stack = (SingleLinkedStack*)GearImpl(context, Stack, stack);
|
|
59 Data* data = Gearef(context, Stack)->data;
|
|
60 enum Code next = Gearef(context, Stack)->next;
|
|
61 goto pushSingleLinkedStack(context, stack, data, next);
|
|
62 }
|
|
63
|
|
64 __code popSingleLinkedStack(struct Context *context,struct SingleLinkedStack* stack, enum Code next,union Data **O_data) {
|
|
65 Data* data __attribute__((unused)) = *O_data;
|
|
66 if (stack->top) {
|
|
67 data = stack->top->data;
|
|
68 stack->top = stack->top->next;
|
|
69 } else {
|
|
70 data = NULL;
|
|
71 }
|
|
72 *O_data = data;
|
|
73 goto meta(context, next);
|
|
74 }
|
|
75
|
|
76 __code popSingleLinkedStack_stub(struct Context* context) {
|
|
77 SingleLinkedStack* stack = (SingleLinkedStack*)GearImpl(context, Stack, stack);
|
|
78 enum Code next = Gearef(context, Stack)->next;
|
|
79 Data** O_data = &Gearef(context, Stack)->data;
|
|
80 goto popSingleLinkedStack(context, stack, next, O_data);
|
|
81 }
|
|
82
|
|
83 __code pop2SingleLinkedStack(struct Context *context,struct SingleLinkedStack* stack, enum Code next,union Data **O_data,union Data **O_data1) {
|
|
84 Data* data __attribute__((unused)) = *O_data;
|
|
85 Data* data1 __attribute__((unused)) = *O_data1;
|
|
86 if (stack->top) {
|
|
87 data = stack->top->data;
|
|
88 stack->top = stack->top->next;
|
|
89 } else {
|
|
90 data = NULL;
|
|
91 }
|
|
92 if (stack->top) {
|
|
93 data1 = stack->top->data;
|
|
94 stack->top = stack->top->next;
|
|
95 } else {
|
|
96 data1 = NULL;
|
|
97 }
|
|
98 *O_data = data;
|
|
99 *O_data1 = data1;
|
|
100 goto meta(context, next);
|
|
101 }
|
|
102
|
|
103
|
|
104 __code pop2SingleLinkedStack_stub(struct Context* context) {
|
|
105 SingleLinkedStack* stack = (SingleLinkedStack*)GearImpl(context, Stack, stack);
|
|
106 enum Code next = Gearef(context, Stack)->next;
|
|
107 Data** O_data = &Gearef(context, Stack)->data;
|
|
108 Data** O_data1 = &Gearef(context, Stack)->data1;
|
|
109 goto pop2SingleLinkedStack(context, stack, next, O_data, O_data1);
|
|
110 }
|
|
111
|
|
112 __code getSingleLinkedStack(struct Context *context,struct SingleLinkedStack* stack, enum Code next,union Data **O_data) {
|
|
113 Data* data __attribute__((unused)) = *O_data;
|
|
114 if (stack->top) {
|
|
115 data = stack->top->data;
|
|
116 } else {
|
|
117 data = NULL;
|
|
118 }
|
|
119 *O_data = data;
|
|
120 goto meta(context, next);
|
|
121 }
|
|
122
|
|
123 __code getSingleLinkedStack_stub(struct Context* context) {
|
|
124 SingleLinkedStack* stack = (SingleLinkedStack*)GearImpl(context, Stack, stack);
|
|
125 enum Code next = Gearef(context, Stack)->next;
|
|
126 Data** O_data = &Gearef(context, Stack)->data;
|
|
127 goto getSingleLinkedStack(context, stack, next, O_data);
|
|
128 }
|
|
129
|
|
130 __code get2SingleLinkedStack(struct Context *context,struct SingleLinkedStack* stack, enum Code next,union Data **O_data,union Data **O_data1) {
|
|
131 Data* data __attribute__((unused)) = *O_data;
|
|
132 Data* data1 __attribute__((unused)) = *O_data1;
|
|
133 if (stack->top) {
|
|
134 data = stack->top->data;
|
|
135 if (stack->top->next) {
|
|
136 data1 = stack->top->next->data;
|
|
137 } else {
|
|
138 data1 = NULL;
|
|
139 }
|
|
140 } else {
|
|
141 data = NULL;
|
|
142 data1 = NULL;
|
|
143 }
|
|
144 *O_data = data;
|
|
145 *O_data1 = data1;
|
|
146 goto meta(context, next);
|
|
147 }
|
|
148
|
|
149 __code get2SingleLinkedStack_stub(struct Context* context) {
|
|
150 SingleLinkedStack* stack = (SingleLinkedStack*)GearImpl(context, Stack, stack);
|
|
151 enum Code next = Gearef(context, Stack)->next;
|
|
152 Data** O_data = &Gearef(context, Stack)->data;
|
|
153 Data** O_data1 = &Gearef(context, Stack)->data1;
|
|
154 goto get2SingleLinkedStack(context, stack, next, O_data, O_data1);
|
|
155 }
|
|
156
|
|
157 __code isEmptySingleLinkedStack(struct Context *context,struct SingleLinkedStack* stack, enum Code next, enum Code whenEmpty) {
|
|
158 if (stack->top) {
|
|
159 goto meta(context, next);
|
|
160 } else {
|
|
161 goto meta(context, whenEmpty);
|
|
162 }
|
|
163 }
|
|
164
|
|
165
|
|
166 __code isEmptySingleLinkedStack_stub(struct Context* context) {
|
|
167 SingleLinkedStack* stack = (SingleLinkedStack*)GearImpl(context, Stack, stack);
|
|
168 enum Code next = Gearef(context, Stack)->next;
|
|
169 enum Code whenEmpty = Gearef(context, Stack)->whenEmpty;
|
|
170 goto isEmptySingleLinkedStack(context, stack, next, whenEmpty);
|
|
171 }
|
|
172
|