05.11.2016, 22:42
How I can order from highest to lowest values?
new i,j,a;
for (i = 0; i < sizeof(number);i++)
{
for (j = i + 1; j < sizeof(number); j++)
{
if (number[i] < number[j])//to sort in reverse (ascending change < to >)
{
a = number[i];
number[i] = number[j];
number[j] = a;
}
}
}
// ** INCLUDES
#include <a_samp>
// ** MAIN
main()
{
print("Loaded \"sort_values_in_array.amx\"."); // 430
/*
new tick = GetTickCount();
for(new i = 0; i < 50000; i ++)
{
new array[] = {30, 100, 20, 40, 5, 23, 56, 21, 2000, 40, 60, 20, 70, 80, 290, 5000};
SortValuesInArray(array);
}
printf("%d", GetTickCount() - tick);
*/
///*
new array[] = {30, 100, 20, 40, 5, 23, 56, 21, 2000, 40, 60, 20, 70, 80, 290, 5000};
SortValuesInArray(array);
for(new i = 0; i < sizeof(array); i ++)
{
printf("%d", array[i]);
}
//*/
}
// ** CALLBACKS
public OnGameModeInit()
{
return 1;
}
public OnGameModeExit()
{
return 1;
}
// ** FUNCTIONS
stock SortValuesInArray(array[], size_of = sizeof(array))
{
for(new i = (size_of - 1), j, temp; i != 0; i --)
{
for(j = 0; j < i; j ++)
{
if(array[i] < array[j])
{
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
return 1;
}