24.12.2011, 17:58
Fasted Bubble Sort made my
Olб,
consegui criar uma versгo mais rбpida a minha antiga funзгo a bubbleSort.
esta funзгo tem no intuito de classificar players(ranking).
pawn Код:
stock BubbleSort(v[], size)
{
new t = 0;
for(new i = 1, j = (size); i != j; ++i)
{
for(new q = 0; (q != size - i); ++q)
t = ((v[i] > v[q]) ? (t = v[i], v[i] = v[q], v[q] = t) : (0));
}
}
Usagem:
pawn Код:
new scoris[MAX_PLAYERS];
for(new i; i != MAX_PLAYERS; ++i)scoris[i] = GetPlayerScore(i);
BubbleSort(scoris, sizeof(scoris));
new str[100], n[24];
for(new i; i != MAX_PLAYERS; ++i)
{
GetPlayerName(i, n, 24);
format(str, sizeof(str),"NЄ%d Nome: %s Pontos:",i+1, n, scoris[i]);
SendClientMessage(playerid, -1, str);
}
Debug

pawn Код:
new scores[100] = {10, 6547, 987, 657, 87521};
BubbleSort(scores, sizeof(scores));
for(new i; i != 10; ++i)
{
printf("ID: %i | Score: %d", i, scores[i]);
}