Jump to content
  • Advertisement
Sign in to follow this  
EvilNando

Need an efficient sorting algorithm

This topic is 3617 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need to sort a 2d-array of Points (struct { int X; int Y; }; ) I dont want to implement a bubble sort because the array can get as big as 999x999 any recomendations? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
So the first problem I see is that points in 2D don't have a well defined ordering to begin with. How do you want the points ordered? Sorted by X then Y, sorted by Y then X, sorted by the sum of X and Y, with respect to some space filling curve... etc.? Once you distill your comparison operator, then you can use any classical efficient sorting algorithm (something thats O(n lg n)). For example, merge sort is a fast, classical comparison based sorting algorithm that would be pretty easy to implement. You could find most of the necessary resources for mergesort anywhere on the web (the wikipedia page is a good place to start).

Cheers,
Rob

Share this post


Link to post
Share on other sites
Thank you very much for the comments

at the end I got smart enough (thanks to mr. cofee) to see that I actually didn't need to sort anything, just a copy in inverse order will do

but thanks a lot

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!