Solved

# Output the last run of a recursive function???

Posted on 2003-11-11

I made a recursive function called MinimumObject, which searches a vector of objects for the alphabetically lowest value.

It works by splitting the vector in two until there are only 1 or 2 elements then compares them.

If I "cout" the values in my FindMin function as I have done below, I am given a list of the smaller of 2 strings and the last one is my minimum. But how do I output just the last value and not the full list?

I have int mode because I was trying to have the comments show up only in mode = 1 and have mode 2 show just the answer. But after hours and hours of trying different combinations of if(mode == 1 or 2) statements I still can't figure out how to go about outputting the last value by its self.

please someone help me

string MinimumObject(vector<Associate> &Members, string key, int mode)

{

vector<Associate> Members2;

if (Members.size() == 0)

return "NULL";

if (Members.size() == 1)

{

return Members[0].getKey(key);

}

if (Members.size() == 2)

{

return FindMin(Members[0].getKey(key), Members[1].getKey(key));

}

else

{

Members2 = split(Members); // Split Members vector in 2

return FindMin(MinimumObject(Members, key, mode), MinimumObject(Members2, key, mode));

}

}

//********************************************************

//INPUT: Two strings

//OUTPUT: Returns the alphabeticly lowest value of the 2 strings.

string FindMin(string a, string b)

{

bool first = (a<=b);

if (first)

{

cout<<a<<"\n";

return a;

}

else

{

cout<<b<<"\n";

return b;

}

}