Linear search looks like the following in pseudocode: |
Here is sample implementation in Ruby: |
Input is a list L and a value V. L[x] will denote the xth element in L, which consists of N values, L[1], L[2], ..., L[N]. function linear-search(L,N,V) set index = 1 repeat while index <= N if L[index] = V return success end-if set index = index + 1 end-repeat return failure end-function |
|
/Talk? |
/Talk? |