@Ravi: checkout this code...i have created tree where there is sharing of nodes..
here is my code :- please let me know is case you find any bug. #include<stdio.h> typedef struct tree{ int idx; float data; struct tree *left; struct tree *right; }node; node *createNode(int index) { node *temp; temp=(node *)malloc(sizeof(node)); temp->idx=index; temp->data=0.0; temp->left=temp->right=NULL; return temp; } void inorder(node *root) { if(root!=NULL) { inorder(root->left); printf("%d ) %f \n",root->idx,root->data); inorder(root->right); } } node* fillCup(node *root,float pour,float capacity) { float temp; if(root==NULL) return NULL; if(root->data+pour >= capacity) { if(root->data==0) { root->data=capacity; pour=pour-capacity; } else { temp=capacity-(root->data); root->data=capacity; pour=pour-temp; if(pour==0) { return root; } } } else { root->data+=pour; return root; } fillCup(root->left,pour/2,capacity); fillCup(root->right,pour/2,capacity); } int main() { node *root; float pour,capacity; root=createNode(1);//1 root->left=createNode(2);//2 root->right=createNode(3);//3 root->left->left=createNode(4);//4 root->left->left->left=createNode(7);//7 root->right->right=createNode(6);//6 root->right->right->right=createNode(10);//10 root->left->right=createNode(5);//5 root->right->left=root->left->right; root->left->left->right=createNode(8); // 8 root->left->right->left=root->left->left->right; root->left->right->right=createNode(9);//9 root->right->right->left=root->left->right->right; printf("\nEnter capacity = "); scanf("%f",&capacity); printf("\nEnter quantity poured = "); scanf("%f",&pour); fillCup(root,pour,capacity); printf("\nPrinting tree\n\n"); inorder(root); printf("\n\n"); return 1; } -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.