06.12.2009, 16:50
It's called bubble sorting
will print
7 5 5 3 3 2 1
pawn Код:
bubbleSort(array[], length)
{
new i,j;
for(i=0;i<length;i++)
{
for(j=0;j<i;j++)
{
if(array[i]>array[j])
{
new temp=array[i]; //swap
array[i]=array[j];
array[j]=temp;
}
}
}
}
pawn Код:
new array2[] = {1, 5, 3, 7, 5, 3, 2};
bubbleSort(array2, 7);
for(new i = 0; i < 7; i++)
{
printf("%d",array2[i]);
}
7 5 5 3 3 2 1