Author |
Message |
tansey Novice
Joined: Nov 03 2004 Posts: 53 Offline
|
Posted: Thu Mar 03, 2005 12:28 am Post subject: Ranking/sorting algorithm? |
 |
|
|
|
I have a list of stats for players in a txt file. The format is name:stat1:stat2:...:statn:rating:rank such that the players are ranked by their rating, with higher ratings corresponding to lower rankings (rating of 1000 may be ranked #1 where 999 would be #2, etc). The stats are updated after the event is run and therefore the list is in random order.
Can anyone think of a good way to sort/rank the players in the file that's better than (n^2)*logn?
--tansey |
|
Back to top |
|
 |
Mine GO BOOM Hunch Hunch What What

Age:41 Gender: Joined: Aug 01 2002 Posts: 3615 Location: Las Vegas Offline
|
Posted: Thu Mar 03, 2005 1:15 am Post subject: |
 |
|
|
|
Quicksort or Mergesort. Will do it in n * log n. If those sources don't help you, google will find source code for you. |
|
Back to top |
|
 |
tansey Novice
Joined: Nov 03 2004 Posts: 53 Offline
|
Posted: Thu Mar 03, 2005 2:31 am Post subject: |
 |
|
|
|
right, i was assuming that i would use quicksort in my analysis..... |
|
Back to top |
|
 |
Bak ?ls -s 0 in

Age:26 Gender: Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
|
Back to top |
|
 |
Mr Ekted Movie Geek

Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
|
Back to top |
|
 |
Bak ?ls -s 0 in

Age:26 Gender: Joined: Jun 11 2004 Posts: 1826 Location: USA Offline
|
Posted: Thu Mar 03, 2005 12:28 pm Post subject: |
 |
|
|
|
merge sort is stable, and in fact stl's stable_sort function uses merge sort |
|
Back to top |
|
 |
Mr Ekted Movie Geek

Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
Posted: Thu Mar 03, 2005 12:46 pm Post subject: |
 |
|
|
|
Well, it might depend on which implementation then I suppose. I never did make sense to me why merge sort wouldn't be stable. |
|
Back to top |
|
 |
Mine GO BOOM Hunch Hunch What What

Age:41 Gender: Joined: Aug 01 2002 Posts: 3615 Location: Las Vegas Offline
|
Posted: Thu Mar 03, 2005 3:44 pm Post subject: |
 |
|
|
|
Mr Ekted wrote: | Well, it might depend on which implementation then I suppose. I never did make sense to me why merge sort wouldn't be stable. |
Here is a good list of which sorts are stable and which are not. |
|
Back to top |
|
 |
Maverick

Age:40 Gender: Joined: Feb 26 2005 Posts: 1521 Location: The Netherlands Offline
|
Posted: Thu Mar 03, 2005 4:37 pm Post subject: |
 |
|
|
|
Yea.. as Mr. Ekted said.. Better to write your own. I did a few times too; simple for loop comparing chars.  _________________
|
|
Back to top |
|
 |
Mr Ekted Movie Geek

Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
Posted: Thu Mar 03, 2005 6:03 pm Post subject: |
 |
|
|
|
I didn't say write your own. I always use qsort() and implement the compare such that the sort is stable. |
|
Back to top |
|
 |
|