Ruby

Ruby code posted
created at 20 Feb 13:44

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
    def recursive(array, value, low, high)
        if (high < low) then
            return -1 # not found
        end
        mid = low + (high - low) / 2
        if (array[mid] > value) then
            return recursive(array, value, low, mid - 1)
        elsif (array[mid] < value) then
            return recursive(array, value, mid + 1, high)
        else
            return mid # found
        end
    end
424 Bytes in 2 ms with coderay