[HELP] get 10 biggest numbers in an array
#1

sombody have an idia how can i find the biggest 10 numbers in an array?
TNX for the help =]
Reply
#2

Maybe you create a loop that checks what number is bigger than the other... Then save it in arrays....
Reply
#3

Lol , the first ten biggest numbers ? Are you kidding ?
Reply
#4

Quote:
Originally Posted by Щә яә Ґя
Lol , the first ten biggest numbers ? Are you kidding ?
whats the joke?
i will give you an example:
i have an array that contains the numbers:
1
2
7
78
3
8
10
58
56
23
4
7
1
2

and i want to put in another array the first biggest numbers like this:
78
58
56
23
10
8
7
7
4
3
2
2
Reply
#5

It's called bubble sorting

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]);
}
will print
7 5 5 3 3 2 1
Reply
#6

TNX Dude =]
Reply
#7

Bubble sort is just one of many sorting algorithm, and is far to be the best..
Reply
#8

I'm not to sure about this and I've never tried it, but I think this might be relevant/useful for you:

https://sampwiki.blast.hk/wiki/Advanced_Structures#Lists
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)