view src/insert_verification/main.c @ 7:24ae2641fec5

Show tree in llrb
author Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
date Tue, 15 Mar 2016 11:52:37 +0900
parents 3f00d95339a7
children e864ede359cc
line wrap: on
line source

#include <stdio.h>

#include "akashaLLRBContext.h"
#include "akashaCS.h"


void printTree(struct Node* node, int n) {
    if (node != 0) {
        printTree(node->left, n+1);
        for (int i=0;i<n;i++)
            printf("  ");
        printf("key=%d value=%d color=%s\t%p\n", node->key, node->value,/* n, */node->color==0? "R":"B", node);
        printTree(node->right, n+1);
    }
}

__code insertOnce_stub(struct Context* context) {
    goto insertOnce(context, &context->data[Node]->node);
}

__code insertOnce(struct Context* context, struct Node* node) {

    node->key   = rand()%100+1;
    node->value = 100;

    context->next = ShowTree;
    goto meta(context, Put);
}

__code showTree_stub(struct Context* context) {
    goto showTree(context, &context->data[Tree]->tree);
}

__code showTree(struct Context* context, struct Tree* tree) {
    printTree(tree->root, 0);
    puts("");

    goto meta(context, Exit);
}

int main(int argc, char const* argv[]) {
    goto startCode(InsertOnce);
}