# prac0701.rb
# サブルーチン
def bubblesort!(list)
    j = list.size - 1
    while j > 0 do
        i = 0
        while i < j do
            sleep(0.5) # 並列処理の違いを分りやすくするため
            if list[i] > list[i+1]
                tmp = list[i]
                list[i] = list[i+1]
                list[i+1] = tmp
            end
            i += 1
        end
        j -= 1
    end
end

# メインルーチン
t1 = Thread::fork{
    list = [5,3,1,2,4]
    bubblesort!(list)
    p list
}       

t2 = Thread::fork{
    list = [50,30,10,20,40,60]
    bubblesort!(list)
    p list
}

t3 = Thread::fork{
    list = [500,300,100]
    bubblesort!(list)
    p list
}

t4 = Thread::fork{
    list = [5,3,1,2,5,6,7]
    bubblesort!(list)
    p list
}

t5 = Thread::fork{
    list = [1,5,4]
    bubblesort!(list)
    p list
}

t1.join
t2.join
t3.join
t4.join
t5.join