added code to ensure 42 in list
This commit is contained in:
@@ -21,8 +21,9 @@ class Search:
|
|||||||
for _ in range(n):
|
for _ in range(n):
|
||||||
array.append(random.randint(0, 1000))
|
array.append(random.randint(0, 1000))
|
||||||
|
|
||||||
# if 42 not in data:
|
#I added this for testing purposes, to make sure 42 was in the list
|
||||||
# data[random.randint(0, n - 1)] = 42
|
if 42 not in array:
|
||||||
|
array[random.randint(0, n - 1)] = 42
|
||||||
|
|
||||||
return array
|
return array
|
||||||
|
|
||||||
@@ -34,7 +35,7 @@ class Search:
|
|||||||
for value in arr:
|
for value in arr:
|
||||||
if value == target:
|
if value == target:
|
||||||
print("Unsuccessful checks:", checks)
|
print("Unsuccessful checks:", checks)
|
||||||
|
return checks
|
||||||
checks += 1
|
checks += 1
|
||||||
|
|
||||||
print("Not found.")
|
print("Not found.")
|
||||||
@@ -98,7 +99,7 @@ def main():
|
|||||||
n = 1000
|
n = 1000
|
||||||
arr = search.generate_random_list(n) #generate the list of n random integers
|
arr = search.generate_random_list(n) #generate the list of n random integers
|
||||||
|
|
||||||
for multiplier in [0.5, 1, 2, 4]:
|
for multiplier in [0.5, 1, 2, 4]: #I used a "multiplier" to avoid rewriting the code for each query
|
||||||
query_count = int(n * multiplier)
|
query_count = int(n * multiplier)
|
||||||
queries = []
|
queries = []
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user