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)
void ll(node *r, node **head){
ReplyDeletestatic 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);
}
@jainendra what is next in the node context.is it part of struct node.
ReplyDeleteyes, it is the extra field in the node of the tree.
ReplyDelete@jainendra:
ReplyDeletethe last two calls should be lyk dis,
ll(r->left,head);
ll(r->right,head);
@kamakshi head argument is missing from last two calls.
ReplyDelete@priyaranjan:
ReplyDeleteya it is missing but two arguments should be passed to function ll.