[SOLVED] Sorting function
#1

Solved

Reply
#2

Hm.. "bump?"
Reply
#3

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;
            }

        }

    }

}
Reply
#4

Yes but i need position of first biggest number, second etc too
Reply
#5

indexes 0, 1, 2, 3 ...
Reply
#6

Why would you use bubble sort? ****** posted a quick sort function here.

For 10000 sorts
Bubble sort: 12307 ms
Quick sort: 1685 ms

pawn Код:
#include <a_samp>

#define ITTERATIONS     10000

public OnFilterScriptInit()
{
    new array[100],
        sortme[sizeof(array)],
        tick;

    for(new i; i < sizeof(array); i++) {
        array[i] = random(0);
    }

   
    tick = GetTickCount();
    for(new i; i < ITTERATIONS; i++) {
        sortme = array;
        bubbleSort(sortme, sizeof(sortme));
    }
    tick = GetTickCount() - tick;
    printf("Bubble sort: %i", tick);

    tick = GetTickCount();
    for(new i; i < ITTERATIONS; i++) {
        sortme = array;
        QSort(sortme, 0, sizeof(sortme) - 1);
    }
    tick = GetTickCount() - tick;
    printf("Quick sort: %i", tick);
    return 1;
}
Reply
#7

we tested sortings in our school with 100000 numbers, for seledtion sort it too 40000ms (40sec) and for merge and quick arround 34ms, so you say quick used 1000+ms for 10k nmbers, i cant belive it.
Reply
#8

Quote:
Originally Posted by TMasters.ProRP
we tested sortings in our school with 100000 numbers, for seledtion sort it too 40000ms (40sec) and for merge and quick arround 34ms, so you say quick used 1000+ms for 10k nmbers, i cant belive it.
That would have been in c or something, pawn is slower. If only I had posted the code or something so you could test it yourself...
Reply
#9

Quote:
Originally Posted by Dabombber
Quote:
Originally Posted by TMasters.ProRP
we tested sortings in our school with 100000 numbers, for seledtion sort it too 40000ms (40sec) and for merge and quick arround 34ms, so you say quick used 1000+ms for 10k nmbers, i cant belive it.
That would have been in c or something, pawn is slower. If only I had posted the code or something so you could test it yourself...
True, and that sux, but taht long, man, i rly didnt think so, whats the CPU speed of the computer? 200MHz? rofl
Reply
#10

Solved
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)