... | ... |
@@ -4,10 +4,6 @@ Hayden Walker |
4 | 4 |
21 July 2020 |
5 | 5 |
''' |
6 | 6 |
|
7 |
-# The array and the target |
|
8 |
-myArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] |
|
9 |
-target = 11 |
|
10 |
- |
|
11 | 7 |
def binarySearch(top, bottom, target): |
12 | 8 |
# Try and look for the target |
13 | 9 |
try: |
... | ... |
@@ -22,6 +18,10 @@ def binarySearch(top, bottom, target): |
22 | 18 |
|
23 | 19 |
# If the program reaches max recursion depth, the target isn't there |
24 | 20 |
except: |
25 |
- return "null" |
|
21 |
+ return None |
|
22 |
+ |
|
23 |
+# The array and the target |
|
24 |
+myArray = [1, 8, 9, 12, 16, 82, 92, 120] |
|
25 |
+target = 0 |
|
26 | 26 |
|
27 | 27 |
print(binarySearch(len(myArray), 0, target)) |
... | ... |
@@ -35,7 +35,7 @@ Binary Search Algorithm (21 July 2020) |
35 | 35 |
*Exception handling |
36 | 36 |
|
37 | 37 |
A binary search algorithm. A sorted array of numbers is given along with a number to search for. The function |
38 |
-will return the position of the target number in the array, or 'null' if it isn't there. Uses recursion. |
|
38 |
+will return the position of the target number in the array, or None if it isn't there. Uses recursion. |
|
39 | 39 |
------------------------------------------------------------------------------------------------------------ |
40 | 40 |
Binary to Decimal Converter (18 August 2019) |
41 | 41 |
*String slicing |