Mercurial > hg > GearsTemplate
comparison src/parallel_execution/SingleLinkedQueue.cbc @ 590:9146d6017f18 default tip
hg mv parallel_execution/* ..
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 16 Jan 2020 15:12:06 +0900 |
parents | a4cab67624f7 |
children |
comparison
equal
deleted
inserted
replaced
589:a4cab67624f7 | 590:9146d6017f18 |
---|---|
1 #include "../context.h" | |
2 #include <stdio.h> | |
3 #interface "Queue.h" | |
4 // use "Node.h" | |
5 // use "Element.h" | |
6 | |
7 Queue* createSingleLinkedQueue(struct Context* context) { | |
8 struct Queue* queue = new Queue(); | |
9 struct SingleLinkedQueue* singleLinkedQueue = new SingleLinkedQueue(); | |
10 queue->queue = (union Data*)singleLinkedQueue; | |
11 singleLinkedQueue->top = new Element(); | |
12 singleLinkedQueue->last = singleLinkedQueue->top; | |
13 queue->take = C_takeSingleLinkedQueue; | |
14 queue->put = C_putSingleLinkedQueue; | |
15 queue->isEmpty = C_isEmptySingleLinkedQueue; | |
16 queue->clear = C_clearSingleLinkedQueue; | |
17 return queue; | |
18 } | |
19 | |
20 void printQueue1(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 printQueue1((union Data*)data->Element.next); | |
27 } | |
28 } | |
29 | |
30 void printQueue(union Data* data) { | |
31 printQueue1(data); | |
32 printf("\n"); | |
33 } | |
34 | |
35 __code clearSingleLinkedQueue(struct SingleLinkedQueue* queue, __code next(...)) { | |
36 queue->top = NULL; | |
37 goto next(...); | |
38 } | |
39 | |
40 __code putSingleLinkedQueue(struct SingleLinkedQueue* queue, union Data* data, __code next(...)) { | |
41 Element* element = new Element(); | |
42 element->data = data; | |
43 element->next = NULL; | |
44 queue->last->next = element; | |
45 queue->last = element; | |
46 goto next(...); | |
47 } | |
48 | |
49 __code takeSingleLinkedQueue(struct SingleLinkedQueue* queue, __code next(union Data* data, ...)) { | |
50 struct Element* top = queue->top; | |
51 struct Element* nextElement = top->next; | |
52 if (queue->top == queue->last) { | |
53 data = NULL; | |
54 } else { | |
55 queue->top = nextElement; | |
56 data = nextElement->data; | |
57 } | |
58 goto next(data, ...); | |
59 } | |
60 | |
61 __code isEmptySingleLinkedQueue(struct SingleLinkedQueue* queue, __code next(...), __code whenEmpty(...)) { | |
62 if (queue->top == queue->last) { | |
63 goto whenEmpty(...); | |
64 } else { | |
65 goto next(...); | |
66 } | |
67 } | |
68 |