Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

linear search

"""
Ordered Linear Search
- This version searches for 1 item, and returns all the occurrences of it
"""
def ord_lin(lst, item):
    found = []
    
    # Search list up to larger number, and get all indices where its found
    for i, num in enumerate(lst): 
        if num > item:
            break
        elif num == item:
            found.append(i)
    return found
Source by www.30secondsofcode.org #
 
PREVIOUS NEXT
Tagged: #linear #search
ADD COMMENT
Topic
Name
4+3 =