I used a queue for storing the nodes of a tree.first the root is pushed in the queue.now till the queue is not empty it pops one node(say x) from the queue and push(x->left and x->right)into the queue only if they are not null.the elements popped out can make a linked list.
Implement a function getbits, that returns the(right adjusted) n bits that begin at position p of an integer. Assume bit position 0 is at the right end and that n and p are sensible positive values.
You are given n real numbers in an array. A number in the array is called a decimal dominant if it occurs more than n/10 times in the array. Give an O(n) time algorithm to determine if the given array has a decimal dominant.
llist(struct node *root)
ReplyDelete{
struct node *r,*p;
struct node *head=NULL;
if(root==NULL)
return;
else{
push(queue,root);
while(queue is not empty)
{
r=pop(queue);
if(r->left!=NULL)
push(queue,r->left);
if(r->right!=NULL)
push(queue,r->right);
if(head==NULL)
{
head=r;
r->next=NULL;
p=r;
}
else{
p->next=r;
r->next=NULL;
p=r;
}
}
}
return;
}
@kamakshi can you explain your approach,because reading code is little bit time taking.:)
ReplyDeleteI used a queue for storing the nodes of a tree.first the root is pushed in the queue.now till the queue is not empty it pops one node(say x) from the queue and push(x->left and x->right)into the queue only if they are not null.the elements popped out can make a linked list.
ReplyDelete