def merge(a,b) c = Array.new(a.length()+b.length()) ia =0 ib =0 ic =0 while ia < a.length() && ib < b.length() if a[ia] < b[ib] c[ic] = a[ia] ia = ia + 1 else c[ic] = b[ib] ib = ib + 1 end ic = ic + 1 end while ia< a.length() c[ic]=a[ia] ia = ia + 1 ic = ic + 1 end while ib< b.length() c[ic]=b[ib] ib = ib + 1 ic = ic + 1 end c end
def merge(a,b) c = Array.new(a.length()+b.length()) ia =0 ib =0 ic =0 while ia < a.length() && ib < b.length() if a[ia] < b[ib] c[ic] = a[ia] ia = ia + 1 else c[ic] = b[ib] ib = ib + 1 end ic = ic + 1 end if ia< a.length() for i in ia..(a.length()-1) c[ib+i]=a[i] end else for i in ib..(b.length()-1) c[ia+i]=b[i] end end c end
ruby vote.rb 選択肢番号のように使う.