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