forming a link in a tree - Unix

This is a discussion on forming a link in a tree - Unix ; Hi Everyone, I was trying out the following problem in recursive approach 10 4 12 6 7 So the link should be 10->4->6->7->12 I developed the following code, for this, void single(struct node * root, struct node * parent) { ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: forming a link in a tree

  1. forming a link in a tree

    Hi Everyone,

    I was trying out the following problem in recursive approach

    10
    4 12
    6
    7

    So the link should be 10->4->6->7->12

    I developed the following code, for this,

    void single(struct node * root, struct node * parent)
    {
    if(root == NULL) return;
    root->link = NULL;
    if(parent != NULL) parent->link = root;
    single(root->lptr,root);
    if(root->lptr != NULL)
    {
    struct node * temp = root->lptr;
    while(temp->rptr!= NULL) temp = temp->rptr;
    single(root->rptr,temp);
    }
    else single(root->rptr,root);
    }

    But i felt this to be a bit clumsy although logic seems fine... is
    there any scope to improve the logic?

  2. Re: forming a link in a tree

    This is not the right newsgroup for this. This looks like a homework
    problem.

    That being said, you must be trying to do an inorder traversal. Check
    out: http://en.wikipedia.org/wiki/Tree_traversal .

+ Reply to Thread