   Need a little help with sorting algorithms
  Hi,I'm not really good with sorting algorithmes, and I have to choose one, so I was hoping someone could advise me. Here's the situation :I have a structure which stores entities. This structure implements all the comparison operators (<, >, <=, etc.) I have a vector of those structures which is rebuild from scratch each frame and I need to sort it.There are a lot of algo out there, some are better than others in a given situation. And I'm looking for the algo which is most suited in my case.Thx in advance for any help / pointers / advice.   
  If you are using C++ you can use the quicksort algorithm built-in through the STL:std::sort[ vEntities.begin[], vEntities.end[] ]PS: square brackets should be rounded but my keyboard is fu. You must include <algorithm> for this by the way.Illco   ;  wow, fast reply, thanks ^^I was already considering this algorithm, but I was wondering if it was the most suited algo in my case. I'll use that if their isn't any better algorithm.   ;  The sorting algorithm you chose depends on a lot of factors, like how many elements you need to sort on average, how sorted the data already is, and the nature of the data itself.  There really are a bunch of different algorithms, each one suited for different purposes, so head over here and check out some of the more common ones.  I see you're careful not to jump on the quicksort bandwagon so soon, which is a good thing.  But admittedly it works very well a lot of the time.   ;  I'd say to use std::sort.If that really isn't fast enough you can switch to a more appropriate sorting algorihm - but what do you want to do - write sorting algorithms or games?   ;  std::sort should do fine. If you have any performance concerns then you're probably going to get more speedup by taking advantage of frame coherency, and not completely rebuilding the vector from scratch each time, than switching algorithm.   ;Quote:Original post by paicI have a vector of those structures which is rebuild from scratch each frameWhy is this being done? (Oh, and yes, use std::sort.)   ;  Use std::set or std::multi_set.FYI, std::sort most likely uses introsort, which is a combination of quicksort and heapsort.   ;  If it has to be rebuilt every frame (Are you sure there is no way around this? It can be a significant cost), and if it is rebuilt completely unsorted, Quicksort is probably your best bet.If the list is mostly sorted to begin with, Quicksort is a bad idea (Randomized quicksort is less horrible in this case, but still not optimal)   ;  Thx for the replies. As many of you seems to say that std::sort is pretty good, and since I'm using std::vector, I used std::sort() for the moment (easy to implement and seems pretty good ^^)   