Um, I want to do it so that it finds the median according to the set size. Haven't accounted for even set size tho.
Like if the set size for both set 1 and set 2 is 21 , the median value should be in the 11th one.
In myset1, the values are ... 10, 20, 30, 40, 50, 60, 70, 80, 90, 100.
In myset2, the values are ...5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55.
Ideally, the median value should be 40.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
int getMedium (set <int> myset1, set <int> myset2)
{
int setsize = myset1. size () + myset2. size ();
setsize = setsize / 2;
set<int>::iterator it1 = myset1. begin ();
set<int>:: iterator it2 = myset2. begin ();
set<int>:: iterator it3;
while ( (it1 != myset1. end ()) && it2 != myset2. end () )
{
if (*it1 > *it2)
{
it1++;
}
else
{
it2++;
}
it3++;
}
cout << "Median Value is " << *it3;
}
|
Here is what I got so far with a different approach. It is displaying 50. Still pretty confused as well.