I want to sort an array of structures based on one of their members. I did this using a sort I wrote, and it works, but I recently discovered that sort() from the standard is about 200 times faster. So I want to sort my stuff with std::sort but I don't know how to use std::sort with an array of structures, sorting based only on a certain member from the structure. I don't even know if it's possible to do this.
Any help would be appreciated, thanks
the code from my slow-slow-slow sort function, if it's of any use to give you the idea:
Code:int minVal = 0; int minPos; NPC tmp; for (int u = 0; u < MainMap.numNPCs-1; ++u) { minPos = -1; for (int v = u; v < MainMap.numNPCs; ++v) { if (NPCs[v].aPixY < minVal || minPos == -1) { minVal = NPCs[v].aPixY; minPos = v; } } tmp = NPCs[u]; NPCs[u] = NPCs[minPos]; NPCs[minPos] = tmp; }



LinkBack URL
About LinkBacks


