Mercurial > hg > GearsTemplate
comparison src/parallel_execution/SingleLinkedQueue.cbc @ 266:ffcd80cc3a83
create SingleLinkedQueue.cbc
author | mir3636 |
---|---|
date | Sat, 28 Jan 2017 23:12:44 +0900 |
parents | |
children | 68cf983475e7 |
comparison
equal
deleted
inserted
replaced
265:4ccf776db994 | 266:ffcd80cc3a83 |
---|---|
1 #include "../context.h" | |
2 #include "../origin_cs.h" | |
3 #include <stdio.h> | |
4 | |
5 Queue* createSingleLinkedQueue(struct Context* context) { | |
6 struct Queue* queue = new Stack(); | |
7 struct SingleLinkedQueue* singleLinkedQueue = new SingleLinkedQueue(); | |
8 queue->queue = (union Data*)singleLinkedQueue; | |
9 singleLinkedQueue->top = NULL; | |
10 singleLinkedQueue->last = NULL; | |
11 queue->take = C_takeSingleLinkedQueue; | |
12 queue->put = C_putSingleLinkedQueue; | |
13 queue->isEmpty = C_isEmptySingleLinkedQueue; | |
14 queue->clear = C_clearSingleLinkedQueue; | |
15 return queue; | |
16 } | |
17 | |
18 void printQueue1(union Data* data) { | |
19 struct Node* node = &data->Element.data->Node; | |
20 if (node == NULL) { | |
21 printf("NULL"); | |
22 } else { | |
23 printf("key = %d ,", node->key); | |
24 printQueue1((union Data*)data->Element.next); | |
25 } | |
26 } | |
27 | |
28 void printQueue(union Data* data) { | |
29 printQueue1(data); | |
30 printf("\n"); | |
31 } | |
32 | |
33 __code clearSingleLinkedQueue(struct SingleLinkedQueue* queue, __code next(...)) { | |
34 queue->top = NULL; | |
35 goto next(...); | |
36 } | |
37 | |
38 __code putSingleLinkedQueue(struct SingleLinkedQueue* queue, union Data* data, __code next(...)) { | |
39 Element* element = new Element(); | |
40 element->next = NULL; | |
41 element->data = data; | |
42 if (queue->last) { | |
43 Element* last = queue->last; | |
44 last->next = element; | |
45 queue->last = element; | |
46 } else { | |
47 queue->top = element; | |
48 queue->last = element; | |
49 } | |
50 goto next(...); | |
51 } | |
52 | |
53 __code takeSingleLinkedQueue(struct SingleLinkedQueue* queue, _code next(union Data* data, ...)) { | |
54 if (queue->top) { | |
55 data = queue->top->data; | |
56 queue->top = queue->top->next; | |
57 } else { | |
58 data = NULL; | |
59 } | |
60 goto next(data, ...); | |
61 } | |
62 | |
63 __code isEmptySingleLinkedQueue(struct SingleLinkedQueue* queue, __code next(...), __code whenEmpty(...)) { | |
64 if (queue->top) | |
65 goto next(...); | |
66 else | |
67 goto whenEmpty(...); | |
68 } | |
69 |