Ask your own question, for FREE!
Computer Science 7 Online
OpenStudy (anonymous):

this is my program to list the number of inversions and print them, i think everything about the code is ok but smthin s wrong it doesnt work....can any1 please check code for me?

OpenStudy (anonymous):

OpenStudy (anonymous):

@mattfeury

OpenStudy (anonymous):

@infinity_ @NeThWa @ktobah

OpenStudy (anonymous):

my final code please check this it gives some random out put

OpenStudy (anonymous):

you know, there is no need to implement merge sort every time you need to sort something :P.Try using standard functions which sort and then count the inversions.

OpenStudy (anonymous):

I can't understand your code sorry, but I'm sure you are having a problem with the pointers.

OpenStudy (rsmith6559):

I didn't study your code thoroughly, but a few things stand out to me. In mergesort: mid=(high+low)/2; can cause integer overflows. It's been changed to: mid = ( high - low ) / 2 + low; In list, I'm surprised that ptr1 and ptr2 aren't int*. Comments in the code would help a lot.

OpenStudy (anonymous):

ptr are to get the index of the array.... they are not pointers....mid wud give the same value in both the cases... nd i was trying to implement this in O(nlogn) thanks all for your time :)

OpenStudy (anonymous):

Is your code running now?

OpenStudy (anonymous):

it is running but it doesnt give the req out put

OpenStudy (anonymous):

Now start debugging if you dare... with a code like that, nobody can debug.When you try solving suck a simple problem don't try using the most sophisticated stuff you know.I'ts ridiculous :P,It's such an easy problem.

OpenStudy (anonymous):

such *

OpenStudy (anonymous):

m trying to debug it............

OpenStudy (anonymous):

actually that's the problem...it's such a simple problem but i cant get it right...... if i wonder if i can copy the code everytime......

OpenStudy (anonymous):

@infinity_ i changed the code and this one's a lot better but ther's still a bug in somewer i just cant figure it out..... can u please take a look at it?

OpenStudy (anonymous):

why so complicated? use stl sort.. it is so easily used and it can save you 20 lines of codde

OpenStudy (anonymous):

stl?

OpenStudy (anonymous):

I can't figure it too, but now I think there is a problem in the print function or when you called it inside your program, try to revise this part.

OpenStudy (anonymous):

there are some function which sort.. you don't need to write everything you might need.

OpenStudy (anonymous):

i got this question covered but i still wonder where i went wrong in that file........

OpenStudy (anonymous):

thank you alll

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!