Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Python linear search

arr = [100, 200, 300, 400, 500]
x = 400

def search(arr, x):
    for i in range(len(arr)):
        if arr[i] == x:
            return i
    return -1

print(search(arr, x))
 
PREVIOUS NEXT
Tagged: #Python #linear #search
ADD COMMENT
Topic
Name
5+7 =