Below is a Python function definition for a linear search of a list lst for element. It returns the first index at which element can be found in the list (or None) if element is not in the list. def linearSearch(lst, element): i = 0 for item in lst: if element == item: return i else: i += 1 return None Write a similar MATLAB function linearSearch.m. Your MATLAB function should take as parameters an unsorted list of non-negative integers, and an integer value, and returns the index where that value is first located in the list. (No argument testing is required.) Unlike the Python code which returns None if the value is not in the array, your MATLAB function should return the value -1 if the value is no
Below is a Python function definition for a linear search of a list lst for element. It returns the first index at which element can be found in the list (or None) if element is not in the list.
def linearSearch(lst, element):
i = 0
for item in lst:
if element == item:
return i
else:
i += 1
return None
Write a similar MATLAB function linearSearch.m. Your MATLAB function should take as parameters an unsorted list of non-negative integers, and an integer value, and returns the index where that value is first located in the list. (No argument testing is required.) Unlike the Python code which returns None if the value is not in the array, your MATLAB function should return the value -1 if the value is not found.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images