creating linked list from leaf nodes of a tree

Create a singly linked list from the Leaf nodes from a binary tree. Tree may be balanced or not. Linked list should be created using nodes of tree only.(However you can take extra fields in node of tree)

Comments

  1. void ll(node *r, node **head){
    static node *p=NULL;
    if(r->left==NULL && r->right==NULL){
    if(*head==NULL){*head=r;p=r;return;}
    p->next=r;
    p=r;
    return;
    }

    ll(r->left);
    ll(r->right);
    }

    ReplyDelete
  2. @jainendra what is next in the node context.is it part of struct node.

    ReplyDelete
  3. yes, it is the extra field in the node of the tree.

    ReplyDelete
  4. @jainendra:
    the last two calls should be lyk dis,

    ll(r->left,head);
    ll(r->right,head);

    ReplyDelete
  5. @kamakshi head argument is missing from last two calls.

    ReplyDelete
  6. @priyaranjan:
    ya it is missing but two arguments should be passed to function ll.

    ReplyDelete

Post a Comment

Popular posts from this blog