1. Data Structures and Algorithms (Project 1)
INSTRUCTIONS:
Create a program using the following features:
* Array
* Class
* Specific Sorting Algorithm
* Specific Searching Algorithm
class Array:
def __init__(self, array: list):
self.array = array
def binary(self, num):
low = 0
high = len(self.array) - 1
while low <= high:
mid = low + high
guess = self.array[mid]
if guess == num:
return mid
if guess > num:
high = mid - 1
else:
low = mid + 1
return None
def _smallest(self):
smallest = self.array[0]
smallest_id = 0
for i in range(1, len(self.array)):
if self.array[i] < smallest:
smallest = self.array[i]
smallest_id = i
return smallest_id
def selection(self):
temp = []
for i in range(len(self.array)):
smallest = self._smallest()
temp.append(self.array.pop(smallest))
self.array = temp
arr = Array([0, 3, 5, 6, 8, 44, 11, 4, 88, 55])
arr.selection()
print(arr.array)
print(arr.binary(55))
print(arr.binary(5))
print(arr.binary(66))
Comments
Leave a comment