You are assuming is to be a binary tree, its not. Some nodes will share a common "pour".
On Feb 25, 9:24 pm, atul anand <[email protected]> wrote: > i guess this would work... > n=number of nodes > h=height; > pour=quantity poured; > capacity = capacity of each cup > > n=pow(2,h+1) -1; > call(capacity,pour,0,n) > > node* fillCup(float capacity,float pour,int left,int right) > { > node *root; > int mid; > if(left > right) > return NULL; > > root=(node *)malloc(sizeof(node)); > if(left==right) > { > if(pour >=capacity) > root->data=capacity; > else > root->data=pour; > root->left=root->right=NULL;} > > else > { > mid=left+(right-left)/2; > if(pour >= capacity) > { > root->data=capacity; > pour=pour-capacity; > pour=pour/2;} > > else > { > root->data=pour; > root->left=root->right=NULL; > return root; > > } > > root->left=fillCup(capacity,pour,left,mid-1); > root->right=fillCup(capacity,pour,mid+1,right); > > } > > return root; > > } > > On Sat, Feb 25, 2012 at 5:05 PM, Ravi Ranjan <[email protected]>wrote: > > > > > > > > > |_| > > |_| |_| > > |_| |_| |_| > > |_| |_| |_| |_| > > |_| |_| |_| |_| |_| > > > Each cup has capacity C and once a cup gets full, it drops half extra > > amount to left child and half extra amount to right child > > > for Eg : let' first cups get 2C amount of liquid then extra amount C(2C-C) > > will be divided equally to left and right child cup of next level > > > i.e. C/2 to left child and C/2 to right child > > > Write a function which takes input parameter as amount of liquid poured at > > top (L) and height of particular cup (h) index of that cup (i) and it > > should return amount of liquid absorbed in that cup. > > > source > > >http://www.careercup.com/question?id=12770661 > > > whats exactly the qestion??? > > > -- > > You received this message because you are subscribed to the Google Groups > > "Algorithm Geeks" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]. > > For more options, visit this group at > >http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
