The code for the linear search is below.
def linear_search(src, target_value):
    result = False
    for i in range(len(src)):
        if src[i] == target_value:
            result = True
    return result
def main():
    src = [1, 2, 3, 4, 5]
    target_value = 5
    if linear_search(src, target_value):
        print('Found!')
    else:
        print('Not Found')
if __name__ == '__main__':
    main()
The execution result is as follows.
Found!
Thank you for reading until the end. Let's meet again.
Recommended Posts