Ruby 빗질정렬 구현

1 개요[ | ]

Ruby 빗질정렬 구현
루비 빗질정렬 구현
def comb_sort(a)
    gap=size=a.size
    swapped = true
    while gap !=1 or swapped
        gap = gap*10/13
        if gap<1; gap=1; end
        swapped = false
        for i in (0...size-gap)
            if a[i]>a[i+gap]
                a[i],a[i+gap] = a[i+gap],a[i]
                swapped = true
            end
        end
    end
end
arr = [9,1,22,4,0,-1,1,22,100,10]
comb_sort(arr)
print( arr )
# [-1, 0, 1, 1, 4, 9, 10, 22, 22, 100]

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}