Mercurial > hg > Members > Moririn
view src/parallel_execution/SingleLinkedQueue.cbc @ 462:8d7e5d48cad3
Running CPU examples
author | Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 20 Dec 2017 22:05:08 +0900 |
parents | 394e38952c80 |
children | ac244346c85d |
line wrap: on
line source
#include "../context.h" #include "Queue.h" #include <stdio.h> Queue* createSingleLinkedQueue(struct Context* context) { struct Queue* queue = new Queue(); struct SingleLinkedQueue* singleLinkedQueue = new SingleLinkedQueue(); queue->queue = (union Data*)singleLinkedQueue; singleLinkedQueue->top = new Element(); singleLinkedQueue->last = singleLinkedQueue->top; queue->take = C_takeSingleLinkedQueue; queue->put = C_putSingleLinkedQueue; queue->isEmpty = C_isEmptySingleLinkedQueue; queue->clear = C_clearSingleLinkedQueue; return queue; } void printQueue1(union Data* data) { struct Node* node = &data->Element.data->Node; if (node == NULL) { printf("NULL"); } else { printf("key = %d ,", node->key); printQueue1((union Data*)data->Element.next); } } void printQueue(union Data* data) { printQueue1(data); printf("\n"); } __code clearSingleLinkedQueue(struct SingleLinkedQueue* queue, __code next(...)) { queue->top = NULL; goto next(...); } __code putSingleLinkedQueue(struct SingleLinkedQueue* queue, union Data* data, __code next(...)) { Element* element = new Element(); element->data = data; element->next = NULL; queue->last->next = element; queue->last = element; goto next(...); } __code takeSingleLinkedQueue(struct SingleLinkedQueue* queue, __code next(union Data* data, ...)) { struct Element* top = queue->top; struct Element* nextElement = top->next; if (queue->top == queue->last) { data = NULL; } else { queue->top = nextElement; data = nextElement->data; } goto next(data, ...); } __code isEmptySingleLinkedQueue(struct SingleLinkedQueue* queue, __code next(...), __code whenEmpty(...)) { if (queue->top == queue->last) goto whenEmpty(...); else goto next(...); }