Mercurial > hg > Papers > 2024 > matac-master
view Paper/src/SingleLinkedQueue.cbc @ 24:f0c0e873e3c1
...
author | matac42 <matac@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 12 Jan 2024 18:52:08 +0900 |
parents | |
children | 905910e9fb04 |
line wrap: on
line source
#include "context.h" #include <stdio.h> #impl "Queue.h" as "SingleLinkedQueue.h" #data "Node.h" #data "Element.h" Queue* createSingleLinkedQueue(struct Context* context) { struct Queue* queue = new Queue(); struct SingleLinkedQueue* singleLinkedQueue = new SingleLinkedQueue(); queue->queue = (union Data*)singleLinkedQueue; queue->take = C_takeSingleLinkedQueue; queue->put = C_putSingleLinkedQueue; queue->isEmpty = C_isEmptySingleLinkedQueue; queue->clear = C_clearSingleLinkedQueue; singleLinkedQueue->top = new Element(); singleLinkedQueue->last = singleLinkedQueue->top; return queue; } // ~~省略~~ __code takeSingleLinkedQueue(struct SingleLinkedQueue* queue, __code next(union Data* data, ...)) { printf("take\n"); 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, ...); } // ~~省略~~