viewing paste topic/4321- counting_sort | Athena

Posted on the
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
prontera,155,188,5  script  test counting sort  1_F_MARIA,{
    freeloop true;
    .@total = 25;
    for ( .@i = 0; .@i < .@total; .@i++ )
        .@array[.@i] = .@print$[.@i] = rand(100);
    dispbottom implode( .@print$, "," );
    .@start = gettimetick(0);
    callfunc "counting_sort", .@array, .@output, .@total;
    .@end = gettimetick(0);
    for ( .@i = 0; .@i < .@total; .@i++ )
        .@print$[.@i] = .@output[.@i];
    dispbottom implode( .@print$, "," );
    dispbottom "time used -> "+( .@end - .@start )+" mili-seconds";
    end;
}
 
function    script  counting_sort   {
    .@total = .@size = getarg( 2, getarraysize( getarg(0) ) );
    copyarray .@arr, getarg(0), .@size;
    while ( .@i < .@size ) {
        .@tmp[.@arr[.@i]]++;
        .@i++;
    }
    do {
        .@index = getarraysize(.@tmp) -1;
        .@output[.@size-1] = .@index;
        .@tmp[.@index]--;
        .@size--;
    } while( .@size );
    copyarray getarg(1), .@output, .@total;
    return;
}
 
prontera,158,188,5  script  test counting sort index    1_F_MARIA,{
    freeloop true;
    .@total = 70;
    for ( .@i = 0; .@i < .@total; .@i++ )
        .@array[.@i] = .@print$[.@i] = rand(8);
    dispbottom implode( .@print$, "," );
    .@start = gettimetick(0);
    callfunc "counting_sort_index", .@array, .@output, .@total;
    .@end = gettimetick(0);
    for ( .@i = 0; .@i < .@total; .@i++ )
        .@print$[.@i] = .@array[ .@output[.@i] ];
    dispbottom implode( .@print$, "," );
    dispbottom "time used -> "+( .@end - .@start )+" mili-seconds";
    end;
}
 
function    script  counting_sort_index {
    .@total = .@size = getarg( 2, getarraysize( getarg(0) ) );
    copyarray .@arr, getarg(0), .@size;
    while ( .@i < .@size ) {
        setd ".@index_"+ .@arr[.@i] +"["+( .@tmp[.@arr[.@i]] )+"]", .@i;
        .@tmp[.@arr[.@i]]++;
        .@i++;
    }
    do {
        .@index = getarraysize(.@tmp) -1;
        .@tmp[.@index]--;
        .@out[.@size-1] = getd( ".@index_"+ .@index +"["+( .@tmp[.@index] )+"]" );
        .@size--;
    } while( .@size );
    copyarray getarg(1), .@out, .@total;
    return;
}
Viewed 1323 times, submitted by AnnieRuru.