algorithm for merge sort

by gowtham 2010-02-03 19:57:20

function merge_sort(m)
if length(m) ≤ 1
return m
var list left, right, result

var integer middle = length(m) / 2
for each x in m up to middle
add x to left
for each x in m after middle
add x to right
left = merge_sort(left)
right = merge_sort(right)
if left.last_item > right.first_item
result = merge(left, right)
else
result = append(left, right)
return result

Tagged in:

886
like
0
dislike
0
mail
flag

You must LOGIN to add comments