Create a program using the following features:
* Array
* Class
* Specific Sorting Algorithm
* Specific Searching Algorithm
What is "Specific Sorting Algorithm" and "Specific Searching Algorithm"?
* sorting code that uses a specific sorting process, here is the list of sorting algorithms that you will use
Bubble
Selection
Insertion
Merge
Shell
* searching code that uses a specific searching process, here is the list of searching algorithms that you will use
Linear
Binary
Fibonacci
Jump
#demonstrating bubble sort
def bubble(array):
number = len(array)
for x in range(number):
sortedE = True
for m in range(number - x - 1):
if array[m] > array[m + 1]:
array[m], array[m + 1] = array[m + 1], array[m]
sortedE = False
if sortedE:
break
return array
#demonstrating insertion sort
def insertion(array):
for x in range(1, len(array)):
element = array[x]
m = x - 1
while m >= 0 and array[m] > element:
array[m + 1] = array[m]
m -= 1
array[m + 1] = element
return array
def mergeI(array):
if len(array) < 2:
return array
center = len(array) // 2
return merge(
left=mergeI(array[:center]),
right=mergeI(array[center:]))
def linear(values, SFor):
SAt = 0
Sres = False
while SAt < len(values) and Sres is False:
if values[SAt] == SFor:
Sres = True
else:
SAt = SAt + 1
return Sres
l = [54, 24, 15, 2, 12, 1, 80]
print(linear(l, 2))
print(linear(l, 81))
Comments
Leave a comment