view c/regexParser/printTree.cc @ 108:70069d4647a0 impl-bitvector

implement malloc error checking
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Thu, 19 Nov 2015 17:48:36 +0900
parents 912d7bd51f38
children
line wrap: on
line source

#include <stdio.h>
#include "regexParser.h"

void descendTree(NodePtr n, int d) {
    if (n->right != NULL) {
        d++;
        descendTree(n->right, d);
        d--;
    }
    if (n->tokenType == 'a') {
        printf("%*c%c(%d)\n",d*4, ' ',n->Value.character,n->nodeNumber);
    } else {
        printf("%*c%c\n",d*4, ' ',n->Value.character);
    }

    if (n->left != NULL) {
        d++;
        descendTree(n->left, d);
        d--;
    }
}

void printTree(NodePtr n) {
    puts("---Print Node----");
    int d = 0;
    descendTree(n,d);
    puts("-----------------");
}