[Home]History of Linear search

HomePage | Recent Changes | Preferences

Revision 2 . . December 13, 2001 4:23 am by Taw [ruby code]
Revision 1 . . September 27, 2001 10:27 pm by Dze27 [Initial entry]
  

Difference (from prior major revision) (no other diffs)

Changed: 5c5
Linear search looks like the following in pseudocode:
Here is sample implementation in Ruby:

Changed: 7,18c7,18
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

def linear_search(array,value)
i = 0
while (i < array.size-1)
if (array[i] == value)
return true
end
i += 1
end
return false
end


Changed: 23c23
/Talk?
/Talk?

HomePage | Recent Changes | Preferences
Search: