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?
@mattfeury
@infinity_ @NeThWa @ktobah
my final code please check this it gives some random out put
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.
I can't understand your code sorry, but I'm sure you are having a problem with the pointers.
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.
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 :)
Is your code running now?
it is running but it doesnt give the req out put
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.
such *
m trying to debug it............
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......
@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?
why so complicated? use stl sort.. it is so easily used and it can save you 20 lines of codde
stl?
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.
there are some function which sort.. you don't need to write everything you might need.
i got this question covered but i still wonder where i went wrong in that file........
thank you alll
Join our real-time social learning platform and learn together with your friends!