viewing paste topic/4321- haru comb sort bug | Athena

Posted on the | Last edited on
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
function    script  comb_sort   {
    .@size = getarg(2);
    copyarray .@arr, getarg(0), .@size;
    .@size = .@gap = getarg(2);
    .@gap10 = .@size * 10;
    do {
        if ( .@gap10 > 10 ) {
            .@gap10 = .@gap10 * 10 / 13;
            .@gap = .@gap10 / 10;
        }
        .@i = .@swap = 0;
        while ( .@i + .@gap < .@size ) {
            if ( .@arr[.@i] > .@arr[ .@i + .@gap ] ) {
                .@tmp = .@arr[.@i];
                .@arr[.@i] = .@arr[ .@i + .@gap ];
                .@arr[ .@i + .@gap ] = .@tmp;
                .@swap = 1;
            }
            .@i++;
        }
    } while ( .@swap || .@gap > 10 );
    copyarray getarg(1), .@arr, .@size;
    return;
}
 
prontera,155,185,6  script  test comb sort  100,{
    .@total = 10;
    freeloop 1;
    for ( .@i = 0; .@i < .@total; ++.@i ) {
        .@array[.@i] = rand(100);
    }
    .@time = gettimetick(0);
    callfunc "comb_sort", .@array, .@output, .@total;
    .@endtime = gettimetick(0);
    for ( .@i = 0; .@i < .@total; ++.@i )
        dispbottom .@output[.@i] +"";
    dispbottom "time used -> "+( .@endtime - .@time )+" milli-seconds";
    end;
}
Viewed 1252 times, submitted by AnnieRuru.