view final_pre/src/getMinHeight.c @ 7:0e8b9646d43f

add final_pre
author e155702
date Sun, 17 Feb 2019 05:39:59 +0900
parents
children
line wrap: on
line source

__code getMinHeight_stub(struct Context* context) {
    goto getMinHeight(context, &context->data[Allocate]->allocate, &context->data[AkashaInfo]->akashaInfo);
}

__code getMinHeight(struct Context* context, struct Allocate* allocate, struct AkashaInfo* akashaInfo) {
    const struct AkashaNode* akashaNode = akashaInfo->akashaNode;

    if (akashaNode == NULL) {
        allocate->size = sizeof(struct AkashaNode);
        allocator(context);
        akashaInfo->akashaNode = (struct AkashaNode*)context->data[context->dataNum];

        akashaInfo->akashaNode->height = 1;
        akashaInfo->akashaNode->node   = context->data[Tree]->tree.root;

        goto getMaxHeight_stub(context);
    }

    const struct Node* node = akashaInfo->akashaNode->node;
    if (node->left == NULL && node->right == NULL) {
        if (akashaInfo->minHeight > akashaNode->height) {
            akashaInfo->minHeight  = akashaNode->height;
            akashaInfo->akashaNode = akashaNode->nextAkashaNode;
            goto getMinHeight_stub(context);
        }
    }

    akashaInfo->akashaNode = akashaInfo->akashaNode->nextAkashaNode;

    if (node->left != NULL) {
        allocate->size = sizeof(struct AkashaNode);
        allocator(context);
        struct AkashaNode* left = (struct AkashaNode*)context->data[context->dataNum];
        left->height           = akashaNode->height+1;
        left->node             = node->left;
        left->nextAkashaNode   = akashaInfo->akashaNode;
        akashaInfo->akashaNode = left;
    }

    if (node->right != NULL) {
        allocate->size = sizeof(struct AkashaNode);
        allocator(context);
        struct AkashaNode* right = (struct AkashaNode*)context->data[context->dataNum];
        right->height            = akashaNode->height+1;
        right->node              = node->right;
        right->nextAkashaNode    = akashaInfo->akashaNode;
        akashaInfo->akashaNode   = right;
    }

    goto getMinHeight_stub(context);
}