will your code work for tree attached and for sum =40??
On Fri, May 14, 2010 at 11:44 PM, jalaj jaiswal <[email protected]>wrote: > Strategy: subtract the node value from the sum when recurring down, > and check to see if the remaining sum is 0 when you run out of tree. > let sum be subsum > > int * PathSum(struct node* node, int sum) { > int i=0; > if (subsum == 0) { > return(array); > } > elseif(node==NULL){ > return; > } > else { > array[i++]=node->data; > // otherwise check both subtrees > int subSum = sum - node->data; > return(hasPathSum(node->left, subSum) || > hasPathSum(node->right, subSum)); > > } > } > > > On Fri, May 14, 2010 at 12:39 PM, divya <[email protected]> wrote: > >> write a c code to print the path in a tree sum of whose nodes equals a >> given number.. >> >> -- >> 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]<algogeeks%[email protected]> >> . >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> >> > > > -- > With Regards, > Jalaj Jaiswal > +919026283397 > B.TECH IT > IIIT ALLAHABAD > > -- > 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]<algogeeks%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- yezhu malai vaasa venkataramana Govinda Govinda -- 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.
<<attachment: tree_path.jpg>>
