Mercurial > hg > Members > Moririn
annotate src/parallel_execution/stack.cbc @ 150:7164f59660d4
create .cbc
author | mir3636 |
---|---|
date | Tue, 15 Nov 2016 17:46:29 +0900 |
parents | src/parallel_execution/stack.c@473b7d990a1f |
children | efef5d4df54f |
rev | line source |
---|---|
135 | 1 #include "context.h" |
86 | 2 #include "stack.h" |
131
a4507906938c
Fix compile error but not work
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
130
diff
changeset
|
3 #include "origin_cs.h" |
138 | 4 #include <stdio.h> |
86 | 5 |
150 | 6 Stack* createSingleLinkedStack() { |
7 struct Stack* stack = new Stack(); | |
8 struct SingleLinkedStack* singleLinkedStack = new SingleLinkedStack(); | |
9 stack->stack = singleLinkedStack; | |
132 | 10 singleLinkedStack->top = NULL; |
150 | 11 stack->push = pushSingleLinkedStack; |
12 stack->pop = popSingleLinkedStack; | |
13 stack->pop2 = pop2SingleLinkedStack; | |
14 stack->get = getSingleLinkedStack; | |
15 stack->get2 = get2SingleLinkedStack; | |
16 stack->isEmpty = isEmptySingleLinkedStack; | |
17 stack->clear = clearSingleLinkedStack; | |
18 return stack; | |
86 | 19 } |
20 | |
138 | 21 void printStack1(union Data* data) { |
22 struct Node* node = &data->element.data->node; | |
23 if (node == NULL) { | |
24 printf("NULL"); | |
25 } else { | |
26 printf("key = %d ,", node->key); | |
27 printStack1((union Data*)data->element.next); | |
28 } | |
29 } | |
30 | |
31 void printStack(union Data* data) { | |
32 printStack1(data); | |
33 printf("\n"); | |
34 } | |
35 | |
150 | 36 __code clearSingleLinkedStack(struct SingleLinkedStack* stack,__code next(...)) { |
145
cc071cf1ba85
add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
37 stack->top = NULL; |
150 | 38 goto next(...); |
145
cc071cf1ba85
add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
39 } |
cc071cf1ba85
add stack clear interface
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
144
diff
changeset
|
40 |
150 | 41 __code pushSingleLinkedStack(struct SingleLinkedStack* stack,union Data* data, __code next(...)) { |
42 Element* element = new Element(); | |
130 | 43 element->next = stack->top; |
44 element->data = data; | |
45 stack->top = element; | |
150 | 46 goto next(...); |
86 | 47 } |
48 | |
150 | 49 __code popSingleLinkedStack(struct SingleLinkedStack* stack, union Data** data, __code next(...)) { |
136 | 50 if (stack->top) { |
51 *data = stack->top->data; | |
52 stack->top = stack->top->next; | |
53 } else { | |
54 *data = NULL; | |
55 } | |
150 | 56 goto next(...); |
57 // goto next(data, ...); | |
86 | 58 } |
59 | |
150 | 60 __code pop2SingleLinkedStack(struct SingleLinkedStack* stack, union Data** data, union Data** data1, __code next(...)) { |
136 | 61 if (stack->top) { |
62 *data = stack->top->data; | |
63 stack->top = stack->top->next; | |
64 } else { | |
65 *data = NULL; | |
66 } | |
67 if (stack->top) { | |
68 *data1 = stack->top->data; | |
69 stack->top = stack->top->next; | |
70 } else { | |
71 *data1 = NULL; | |
72 } | |
150 | 73 goto next(...); |
133 | 74 } |
75 | |
150 | 76 __code getSingleLinkedStack(struct SingleLinkedStack* stack, union Data** data, __code next(...)) { |
141
4f6a660c14a1
stack interface worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
140
diff
changeset
|
77 if (stack->top) |
4f6a660c14a1
stack interface worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
140
diff
changeset
|
78 *data = stack->top->data; |
4f6a660c14a1
stack interface worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
140
diff
changeset
|
79 else |
4f6a660c14a1
stack interface worked
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
140
diff
changeset
|
80 *data = NULL; |
150 | 81 goto next(...); |
134
2eccf4564efe
fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
82 } |
2eccf4564efe
fix stack call in rb_tree
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
83 |
150 | 84 __code get2SingleLinkedStack(struct SingleLinkedStack* stack, union Data** data, union Data** data1, __code next(...)) { |
136 | 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; | |
140 | 94 *data1 = NULL; |
136 | 95 } |
150 | 96 goto next(...); |
133 | 97 } |
98 | |
150 | 99 __code isEmptySingleLinkedStack(struct SingleLinkedStack* stack, __code next(...), __code whenEmpty(...)) { |
133 | 100 if (stack->top) |
150 | 101 goto next(...); |
133 | 102 else |
150 | 103 goto whenEmpty(...); |
133 | 104 } |
105 | |
132 | 106 |