poring_w01,90,100,5 script quick sort 1_F_MARIA,{ callfunc "test_sort", "quick"; } poring_w01,92,100,5 script counting sort 1_F_MARIA,{ callfunc "test_sort", "counting"; } poring_w01,94,100,5 script comb sort 1_F_MARIA,{ callfunc "test_sort", "comb"; } function script test_sort { freeloop true; .@total = 1000; for ( .@i = 0; .@i < .@total; ++.@i ) .@array[.@i] = rand(50); .@start = gettimetick(0); callfunc getarg(0), .@array; .@end = gettimetick(0); for ( .@i = 0; .@i < .@total; ++.@i ) .@print$[.@i] = .@array[ .@i ]; debugmes implode( .@print$, "," ); dispbottom "time used -> "+( .@end - .@start )+" mili-seconds"; end; } function script array_shuffle { .@size = getarraysize(getarg(0)); for (.@i = .@size - 1; .@i >= 1; --.@i) swap(getelementofarray(getarg(0), rand(0, .@i)), getelementofarray(getarg(0), .@i)); return true; } // credit to keyworld function script counting { .@total = .@size = getarraysize( getarg(0) ); copyarray .@arr, getarg(0), .@size; for ( .@i = 0; .@i < .@size; ++.@i ) ++.@tmp[.@arr[.@i]]; for ( ; .@size; --.@size ) { .@index = getarraysize(.@tmp) -1; .@output[.@size-1] = .@index; --.@tmp[.@index]; } copyarray getarg(0), .@output, .@total; return; } // credit to meko function script quick { callsub(S_Quicksort, getarg(0), getarrayindex(getarg(0)), getarraysize(getarg(0)) - 1); return true; S_Quicksort: if (getarg(1) < getarg(2)) { .@p = callsub(S_Partition, getarg(0), getarg(1), getarg(2)); callsub(S_Quicksort, getarg(0), getarg(1), .@p - 1); callsub(S_Quicksort, getarg(0), .@p + 1, getarg(2)); } return true; S_Partition: .@i = getarg(1) - 1; for (.@j = getarg(1); .@j <= getarg(2) - 1; ++.@j) if (getelementofarray(getarg(0), .@j) < getelementofarray(getarg(0), getarg(2))) swap(getelementofarray(getarg(0), ++.@i), getelementofarray(getarg(0), .@j)); swap(getelementofarray(getarg(0), ++.@i), getelementofarray(getarg(0), getarg(2))); return .@i; } // credit to haru & keyworld function script comb { .@size = getarraysize( getarg(0) ); .@gap = .@size; do { .@gap = .@gap > 1 ? .@gap * 10 / 13 : .@gap; for ( .@i = .@gap; .@i < .@size; ++.@i ) if ( getelementofarray( getarg(0), .@i - .@gap ) > getelementofarray( getarg(0), .@i ) ) swap getelementofarray( getarg(0), .@i - .@gap ), getelementofarray( getarg(0), .@i ); } while ( .@gap > 1 ); return; } function script printdispbottom { .@size = getarraysize( getarg(1) ); for ( .@i = 0; .@i < .@size; ++.@i ) .@print$ += getelementofarray( getarg(1), .@i )+","; dispbottom getarg(0) +" = "+ .@print$; return; } poring_w01,105,100,5 script debug_sort 1_F_MARIA,{ dispbottom " ==== "+ strnpcinfo(NPC_NAME) +" ==="; setarray .@a, 0,1,2,3,4,5,6,7,8,9, 1,2,5,6,3,8,9,4,6,3,5,6,8,3,5; printdispbottom "original", .@a; array_shuffle .@a; printdispbottom " shuffle", .@a; quick .@a; printdispbottom " sort", .@a; end; } poring_w01,105,105,5 script test string 1_F_MARIA,{ dispbottom ( "test" == "test" ); // return 1 dispbottom ( "123" > "321" ); // return 0 dispbottom ( "asdf" < "qwer" ); // return 1 end; }