lundi 12 juin 2017

Ruby If Statements

def bubble_sort(array)
swaps = 0;
i=0;
last = array.length - 1

while swaps > -1 

    if i == last
        i = 0
        last--
        swaps = 0

        if swaps < 1
            swaps = -1
        end

    end

    if array[i] > array[i+1]
        temp = array[i]
        array[i] = array[i+1]
        array[i+1] = temp
        swaps++
    end

    i++

end

end

What is wrong with this code? Not logical erros but syntactical Im getting these errors: and can't figure out why

bubble_sort.rb:22: syntax error, unexpected keyword_end

bubble_sort.rb:26: syntax error, unexpected keyword_end

Aucun commentaire:

Enregistrer un commentaire