view paper/src/SingleLinkedStack.c @ 72:951cb9681030

add source code
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Thu, 04 Feb 2021 14:54:44 +0900
parents
children
line wrap: on
line source

#include "../context.h"
#include <stdio.h>

Stack* createSingleLinkedStack(struct Context* context) {
    struct Stack* stack  = &ALLOCATE(context, Stack)->Stack;
    struct SingleLinkedStack* single_linked_stack = &ALLOCATE(context, SingleLinkedStack)->SingleLinkedStack;
    stack->stack = (union Data*)single_linked_stack;
    stack->data = NULL;
    stack->data1 = NULL;
    single_linked_stack->top = NULL;
    stack->clear = C_clearSingleLinkedStack;
    stack->push = C_pushSingleLinkedStack;
    stack->pop = C_popSingleLinkedStack;
    stack->pop2 = C_pop2SingleLinkedStack;
    stack->isEmpty = C_isEmptySingleLinkedStack;
    stack->get = C_getSingleLinkedStack;
    stack->get2 = C_get2SingleLinkedStack;
    return stack;
}
// include "Node.h"


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 Context *context,struct SingleLinkedStack* stack,enum Code next) {
    stack->top = NULL;
    goto meta(context, next);
}

__code clearSingleLinkedStack_stub(struct Context* context) {
	SingleLinkedStack* stack = (SingleLinkedStack*)GearImpl(context, Stack, stack);
	enum Code next = Gearef(context, Stack)->next;
	goto clearSingleLinkedStack(context, stack, next);
}

__code pushSingleLinkedStack(struct Context *context,struct SingleLinkedStack* stack, union Data* data, enum Code next) {
    Element* element = &ALLOCATE(context, Element)->Element;
    element->next = stack->top;
    element->data = data;
    stack->top = element;
    goto meta(context, next);
}

__code pushSingleLinkedStack_stub(struct Context* context) {
	SingleLinkedStack* stack = (SingleLinkedStack*)GearImpl(context, Stack, stack);
	Data* data = Gearef(context, Stack)->data;
	enum Code next = Gearef(context, Stack)->next;
	goto pushSingleLinkedStack(context, stack, data, next);
}

__code popSingleLinkedStack(struct Context *context,struct SingleLinkedStack* stack, enum Code next,union Data **O_data) {
	Data* data  __attribute__((unused))  = *O_data;
    if (stack->top) {
        data = stack->top->data;
        stack->top = stack->top->next;
    } else {
        data = NULL;
    }
	*O_data = data;
    goto meta(context, next);
}

__code popSingleLinkedStack_stub(struct Context* context) {
	SingleLinkedStack* stack = (SingleLinkedStack*)GearImpl(context, Stack, stack);
	enum Code next = Gearef(context, Stack)->next;
	Data** O_data = &Gearef(context, Stack)->data;
	goto popSingleLinkedStack(context, stack, next, O_data);
}

__code pop2SingleLinkedStack(struct Context *context,struct SingleLinkedStack* stack, enum Code next,union Data **O_data,union Data **O_data1) {
	Data* data  __attribute__((unused))  = *O_data;
	Data* data1  __attribute__((unused))  = *O_data1;
    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;
    }
	*O_data = data;
	*O_data1 =  data1;
    goto meta(context, next);
}


__code pop2SingleLinkedStack_stub(struct Context* context) {
	SingleLinkedStack* stack = (SingleLinkedStack*)GearImpl(context, Stack, stack);
	enum Code next = Gearef(context, Stack)->next;
	Data** O_data = &Gearef(context, Stack)->data;
	Data** O_data1 = &Gearef(context, Stack)->data1;
	goto pop2SingleLinkedStack(context, stack, next, O_data, O_data1);
}

__code getSingleLinkedStack(struct Context *context,struct SingleLinkedStack* stack, enum Code next,union Data **O_data) {
	Data* data  __attribute__((unused))  = *O_data;
    if (stack->top) {
        data = stack->top->data;
    } else {
        data = NULL;
    }
	*O_data = data;
    goto meta(context, next);
}

__code getSingleLinkedStack_stub(struct Context* context) {
	SingleLinkedStack* stack = (SingleLinkedStack*)GearImpl(context, Stack, stack);
	enum Code next = Gearef(context, Stack)->next;
	Data** O_data = &Gearef(context, Stack)->data;
	goto getSingleLinkedStack(context, stack, next, O_data);
}

__code get2SingleLinkedStack(struct Context *context,struct SingleLinkedStack* stack, enum Code next,union Data **O_data,union Data **O_data1) {
	Data* data  __attribute__((unused))  = *O_data;
	Data* data1  __attribute__((unused))  = *O_data1;
    if (stack->top) {
        data = stack->top->data;
        if (stack->top->next) {
            data1 = stack->top->next->data;
        } else {
            data1 = NULL;
        }
    } else {
        data = NULL;
        data1 = NULL;
    }
	*O_data = data;
	*O_data1 =  data1;
    goto meta(context, next);
}

__code get2SingleLinkedStack_stub(struct Context* context) {
	SingleLinkedStack* stack = (SingleLinkedStack*)GearImpl(context, Stack, stack);
	enum Code next = Gearef(context, Stack)->next;
	Data** O_data = &Gearef(context, Stack)->data;
	Data** O_data1 = &Gearef(context, Stack)->data1;
	goto get2SingleLinkedStack(context, stack, next, O_data, O_data1);
}

__code isEmptySingleLinkedStack(struct Context *context,struct SingleLinkedStack* stack, enum Code next, enum Code whenEmpty) {
    if (stack->top) {
        goto meta(context, next);
    } else {
        goto meta(context, whenEmpty);
    }
}


__code isEmptySingleLinkedStack_stub(struct Context* context) {
	SingleLinkedStack* stack = (SingleLinkedStack*)GearImpl(context, Stack, stack);
	enum Code next = Gearef(context, Stack)->next;
	enum Code whenEmpty = Gearef(context, Stack)->whenEmpty;
	goto isEmptySingleLinkedStack(context, stack, next, whenEmpty);
}