ptn search(int* n, int ni, int nj) {
    ptn root = NULL;
    int nm = (ni+nj)/2;
    if (ni > nj) return NULL;
    root = tn_init(n[nm]);
    root->left = search(n, ni, nm-1);
    root->right = search(n, nm+1, nj);
    return root;
}
ptn search(int* p, int pi, int pj, int* i, int ii, int ij) {
    int lt = 0, rt = 0;
    ptn n = NULL;
    if (pi > pj) return NULL;
    while(i[ii+lt] != p[pi]) lt ++;
    rt = pj-pi-lt;
    n = tn_init(p[pi]);
    n->left = search(p, pi+1, pi+lt, i, ii, ii+lt-1);
    n->right = search(p, pj-rt+1, pj, i, ij-rt+1, ij);
    return n;
}
Exemple #3
0
// Create a new Tree with a single root node
Tree* tree_init(int freq, char c){
    Tree *t = (Tree*) malloc(sizeof(Tree));
    t->root = tn_init(freq, c);
    return t;
}