on MergeList(first_list, last_list)
set spisok to {}
repeat while (first_list is not {}) and (last_list is not {})
if first item of first_list < first item of last_list then
set end of spisok to first item of first_list
set first_list to rest of first_list
else
set end of spisok to first item of last_list
set last_list to rest of last_list
end if
end repeat
return spisok & first_list & last_list
end MergeList
--This works slowly, if one of lists been shorter, because alls the elements are don't care looked through.
on MergeList1(first_list, last_list)
set id_record to 1
set spisok to {}
set count_end to count of last_list
repeat with itm in first_list
repeat with id_record from id_record to count_end
if itm > (item id_record of last_list) then
set end of spisok to item id_record of last_list
set id_record to id_record + 1
else
exit repeat
end if
end repeat
set end of spisok to contents of itm
end repeat
repeat with id_record from id_record to count_end
set end of spisok to item id_record of last_list
end repeat
return contents of spisok
end MergeList1
on MergeSort(spisok)
if (count of spisok) > 1 then
set vsego to (count of spisok) div 2
set spisok to MergeList(MergeSort(items 1 thru vsego of spisok), MergeSort(items (vsego + 1) thru -1 of spisok))
end if
return spisok
end MergeSort
Hi.
There’s a very fast merge sort here in Code Exchange, if it’s of any use to you. It’s an “in place” implementation ” that is, it doesn’t return a result, but sorts the actual list passed to it.
Beautifully, this is equal in 10 time been faster what at me, thank