linear suche algorithmus python programmieren

Solutions on MaxInterview for linear suche algorithmus python programmieren by the best coders in the world

showing results for - "linear suche algorithmus python programmieren"
Davide
03 Jul 2020
1## searching function
2def search_element(arr, n, element):
3
4	## iterating through the array
5	for i in range(n):
6
7		## checking the current element with required element
8		if arr[i] == element:
9			## returning True on match
10			return True
11
12	## element is not found hence the execution comes here
13	return False
14
15
16if __name__ == '__main__':
17	## initializing the array, length, and element to be searched
18	arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
19	n = 10
20	element_to_be_searched = 6
21	# element_to_be_searched = 11
22
23	if search_element(arr, n, element_to_be_searched):
24		print(element_to_be_searched, "is found")
25	else:
26		print(element_to_be_searched, "is not found")
27