Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def BinarySearch(array, search):
- first = 0
- last = len(array)
- IsFound = False
- while first <= last and IsFound == False:
- index = (first + last) // 2
- if array[index] == search:
- return index
- elif array[index] > search:
- last = index - 1
- else:
- first = index + 1
- return -1
- def BubbleSort(array, array2):
- reducingindex = len(array)-1
- for outerindex in range(0, len(array)):
- for index in range(0, reducingindex):
- if array[index+1] < array[index]:
- TempValue = array[index+1]
- TempValue2 = array2[index+1]
- array[index+1] = array[index]
- array2[index+1] = array2[index]
- array[index] = TempValue
- array2[index] = TempValue2
- reducingindex = reducingindex - 1
- return array, array2
- keys = ["Math", "Biology", "Chemistry", "Physics", "UTS", "Philosophy", "English", "Filipino", "Programming", "Computing", "Arts", "PE", "ASF", "NSTP", "History"]
- values = [99,98,97,96,95,94,93,92,91,90,89,88,87,86,85]
- newKeys, newValues = BubbleSort(keys, values)
- find = input("Enter subject: ")
- index = BinarySearch(newKeys, find)
- print(newValues[index])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement