I suppose with floating point numbers you could keep a running average as you go, but why do this extra weirdness when you can get the total and total count recursively? Is it just because that's the assignment?
>>I know it's weird, and yes thats just bcos it was the assignment. You said i could do this with running average, could u plz show me how?That's what i have been trying to do. Unfortunately, i dont remember that running avg thing very well.
using statics and globals really undermines the meaning of a recursive function, in my humble opinion.
>>I do agree with u, and that's why i have been looking for something different.
you could have a class that contains member variables so you don't need globals and statics
>>But this findaverage() was supposed to be a member function of my BST(binary search tree) class. Making another class would somehow complicate things(right?), and the assignment asked us to write only a recursive function to do the job. I had to do it something like this:
int main()
{
BST mytree;
//insert nodes into the tree
cout<<"\nAVERAGE = "<<mytree.FindAverage(mytree.getRoot());//passed the root of tree to the findaverage function
return 0;
}