Jump to content
  • Advertisement
Sign in to follow this  
EvilNando

Need an efficient sorting algorithm

This topic is 3676 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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!