I want to sort 4 players according to their scores (player[0].win through player[3].win) and then display the sorted list as such: A B C D.
What would be an efficient algorithm to solve this problem? The one I'm using is very tedious and takes a lot of space. Here's a quarter of the code snippet:
Code:*pointer = max(max(player[0].pts, player[1].pts), max(player[2].pts, player[3].pts)); if (*pointer == player[0].pts) { pos1 = 'A'; *pointer = max( player[1].pts, max(player[2].pts, player[3].pts)); if (*pointer == player[1].pts) { pos2 = 'B'; *pointer = max( player[2].pts, player[3].pts); if (*pointer == player[2].pts) { pos3 = 'C'; pos4 = 'D'; } else { pos3 = 'D'; pos4 = 'C'; }; } else if (*pointer == player[2].pts) { pos2 = 'C'; *pointer = max( player[1].pts, player[3].pts); if (*pointer == player[1].pts) { pos3 = 'B'; pos4 = 'D'; } else { pos3 = 'D'; pos4 = 'B'; }; } else if (*pointer == player[3].pts) { pos2 = 'D'; *pointer = max( player[1].pts, player[2].pts); if (*pointer == player[1].pts) { pos3 = 'B'; pos4 = 'C'; } else { pos3 = 'C'; pos4 = 'B'; }; } }



LinkBack URL
About LinkBacks


