here is the merge_sort i write in ruby. but it doesn’t produce the

right answer, i can’t find where the problem is . thanks in advance

def merge(a, p, q, r)

a1=a[0…(q-p)]

a2=a[(q-p+1)…r]

a1<<99999999

a2<<99999999

i=j=0

for k in (p…r)

if a1[i]<=a2[j]

a[k]=a1[i]

i=i+1

else

a[k]=a2[j]

j=j+1

end

end

end

def merge_sort(a,p,r)

if p<r

q =(p+r)/2

merge_sort(a,p,q)

merge_sort(a,q+1,r)

merge(a,p,q,r)

end

end

a=[]

10.times {a<<rand(10)}

p a

merge_sort(a,0,9)

p a