I'm currently working on a software project in Swift that requires several different types of sorting mechanisms. I have been searching, to no avail, to find an algorithm to do a sort with tie-breaking. In other words, say you have a data set that could be represented like so:
[Name Of Data]:[Someone's ID]-[Same Someone's Score],[Someone's ID]-[Same Someone's Score],[etc...]\n [Name Of Data]:[Someone's ID]-[Same Someone's Score],[Someone's ID]-[Same Someone's Score],[etc...]\n [etc...]
One line, then, may look like this:
And another looks like this:
I would like to be able to sort the IDs in terms of 'winner', where the 'Wins' criteria is 1st priority, and if there is a tie, the program would move to the 'SpeakerPoints' criteria, and so on...
Ordinarily I would use a platform specific mechanism (like
LINQ for Windows or
NSSortDescriptor for MacOS). However, the project is "Shared Code" that should compile on any platform necessary. If it matters, I'm using
Silver, an implementation of Apple's
Swift that compiles for Windows/MacOS/iOS/Android/etc... targets, so I am basically limited to using "pure swift" (Pure swift code works perfectly well). How might I implement a Sort to do this? I don't care about the algorithm being super efficient (though I don't want a simple sort to take hours either, I could do that myself :P), a modified bubble sort would be fine as long as it returned the correctly sorted ID's.
As a complication, the number of criteria is also a variable: this time it may be
speakerPoints, but next time may include