Mercurial > hg > GearsTemplate
view src/parallel_execution/stack.cbc @ 152:7164f59660d4
create .cbc
author | mir3636 |
---|---|
date | Tue, 15 Nov 2016 17:46:29 +0900 |
parents | src/parallel_execution/stack.c@473b7d990a1f |
children | efef5d4df54f |
line wrap: on
line source
#include "context.h" #include "stack.h" #include "origin_cs.h" #include <stdio.h> Stack* createSingleLinkedStack() { struct Stack* stack = new Stack(); struct SingleLinkedStack* singleLinkedStack = new SingleLinkedStack(); stack->stack = singleLinkedStack; singleLinkedStack->top = NULL; stack->push = pushSingleLinkedStack; stack->pop = popSingleLinkedStack; stack->pop2 = pop2SingleLinkedStack; stack->get = getSingleLinkedStack; stack->get2 = get2SingleLinkedStack; stack->isEmpty = isEmptySingleLinkedStack; stack->clear = clearSingleLinkedStack; return stack; } void printStack1(union Data* data) { struct Node* node = &data->element.data->node; if (node == NULL) { printf("NULL"); } else { printf("key = %d ,", node->key); printStack1((union Data*)data->element.next); } } void printStack(union Data* data) { printStack1(data); printf("\n"); } __code clearSingleLinkedStack(struct SingleLinkedStack* stack,__code next(...)) { stack->top = NULL; goto next(...); } __code pushSingleLinkedStack(struct SingleLinkedStack* stack,union Data* data, __code next(...)) { Element* element = new Element(); element->next = stack->top; element->data = data; stack->top = element; goto next(...); } __code popSingleLinkedStack(struct SingleLinkedStack* stack, union Data** data, __code next(...)) { if (stack->top) { *data = stack->top->data; stack->top = stack->top->next; } else { *data = NULL; } goto next(...); // goto next(data, ...); } __code pop2SingleLinkedStack(struct SingleLinkedStack* stack, union Data** data, union Data** data1, __code next(...)) { if (stack->top) { *data = stack->top->data; stack->top = stack->top->next; } else { *data = NULL; } if (stack->top) { *data1 = stack->top->data; stack->top = stack->top->next; } else { *data1 = NULL; } goto next(...); } __code getSingleLinkedStack(struct SingleLinkedStack* stack, union Data** data, __code next(...)) { if (stack->top) *data = stack->top->data; else *data = NULL; goto next(...); } __code get2SingleLinkedStack(struct SingleLinkedStack* stack, union Data** data, union Data** data1, __code next(...)) { if (stack->top) { *data = stack->top->data; if (stack->top->next) { *data1 = stack->top->next->data; } else { *data1 = NULL; } } else { *data = NULL; *data1 = NULL; } goto next(...); } __code isEmptySingleLinkedStack(struct SingleLinkedStack* stack, __code next(...), __code whenEmpty(...)) { if (stack->top) goto next(...); else goto whenEmpty(...); }