prontera,152,188,5 script test merge sort 100,{ .@total = 10; for ( .@i = 0; .@i < .@total; .@i++ ) .@array[.@i] = rand(100); .@start = gettimetick(0); freeloop 1; callfunc "merge_sort", .@array, .@output, .@total; .@end = gettimetick(0); for ( .@i = 0; .@i < .@total; .@i++ ) dispbottom .@array[ .@output[.@i] ] +""; dispbottom "time used -> "+( .@end - .@start )+" mili-seconds"; end; } prontera,155,188,5 script getitemname2 ID sorted 100,{ freeloop 1; getinventorylist; dispbottom "Merge sort === Total items : "+ @inventorylist_count +" ==="; callfunc "merge_sort", @inventorylist_id, .@output, @inventorylist_count; .@i = 0; while ( .@i < @inventorylist_count ) { .@itemname$ = callfunc("getitemname2", @inventorylist_id[ .@output[.@i] ], @inventorylist_identify[ .@output[.@i] ], @inventorylist_refine[ .@output[.@i] ], @inventorylist_attribute[ .@output[.@i] ], @inventorylist_card1[ .@output[.@i] ], @inventorylist_card2[ .@output[.@i] ], @inventorylist_card3[ .@output[.@i] ], @inventorylist_card4[ .@output[.@i] ]); dispbottom "("+ @inventorylist_id[ .@output[.@i] ] +") "+ .@itemname$ +": "+ @inventorylist_amount[ .@output[.@i] ] +" ea."; .@i++; } end; } // callfunc "merge_sort", , , ; // Credits to Haru -> http://hercules.ws/board/topic/4321- function script merge_sort { .@size = getarg(2); copyarray .@arr, getarg(0), .@size; while ( .@i < .@size ) { set getelementofarray(getarg(1), .@i), .@i; .@i++; } .@width = 1; while ( .@width < .@size ) { .@i = 0; while ( .@i < .@size ) { .@left = .@i; .@middle = .@i + .@width; .@right = .@i + 2*.@width; if (.@size < .@middle) .@middle = .@size; if (.@size < .@right) .@right = .@size; .@i0 = .@left; .@i1 = .@middle; .@j = .@left; while ( .@j < .@right ) { if (.@i0 < .@middle && (.@i1 >= .@right || .@arr[.@i0] <= .@arr[.@i1])) { .@tmp_array[.@j] = .@arr[.@i0]; .@tmp_array2[.@j] = getelementofarray(getarg(1), .@i0); .@i0++; } else { .@tmp_array[.@j] = .@arr[.@i1]; .@tmp_array2[.@j] = getelementofarray(getarg(1), .@i1); .@i1++; } .@j++; } .@i += 2 * .@width; } .@width *= 2; copyarray .@arr, .@tmp_array, .@size; copyarray getarg(1), .@tmp_array2, .@size; } return; }