# 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.

## 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 on other sites
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 on other sites
Your standard library will come with a sort routine. For example, qsort() in C and std::sort() in C++.

##### 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

1. 1
2. 2
Rutin
19
3. 3
khawk
15
4. 4
5. 5
A4L
13

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633744
• Total Posts
3013652
×

## Important Information

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!