Simple median function crashing VS2010, 2008 and gcc

hi

int median(int r){int imed,ibrr;imed = r/2;ibrr = r%2; if(ibrr){imed += 1;} return imed;}

The simple median function above is crashing my program why is it? Its crashing my whole code when I insert it and I don't understand.
How do you mean when you "insert it". Surely just having it as part of your code wouldn't crash your program. There must be some function using the result of median where the crash is occurring, because there doesn't seem to be anything that would crash the program within the function itself.

You will need to post the code that calls median.
It is not the function that crashes your program. It is your code that you did not show that crashes the program.:)
As for the function then it of course can be rewritten that to look more professional.


1
2
3
4
inline int median( int r )
{
   return ( r / 2 + r % 2 );
}
Last edited on
Why does this simple quicksort return the wrong values when I insert it to my function?
*solved
Last edited on
the output is

2 1 4 6 5 3


with the median function inserted why is it?
Maybe the problem is that your code of quick_sort is incorrect.
the median function is wrong since when the array is split lets say on element 4 and 6, I'm passing it the 6 instead then asking it for the median between 6 and 0, which would be out of range.
Topic archived. No new replies allowed.