SHARE
TWEET

asdadwqewqe

a guest Sep 22nd, 2019 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def BinarySearch(array, search):
  2.     first = 0
  3.     last = len(array)
  4.     IsFound = False
  5.  
  6.     while first <= last and IsFound == False:
  7.         index = (first + last) // 2
  8.         if array[index] == search:
  9.             return index
  10.         elif array[index] > search:
  11.             last = index - 1
  12.         else:
  13.             first = index + 1
  14.  
  15.     return -1
  16.  
  17. def BubbleSort(array, array2):
  18.     reducingindex = len(array)-1
  19.  
  20.     for outerindex in range(0, len(array)):
  21.         for index in range(0, reducingindex):
  22.             if array[index+1] < array[index]:
  23.                 TempValue = array[index+1]
  24.                 TempValue2 = array2[index+1]
  25.                 array[index+1] = array[index]
  26.                 array2[index+1] = array2[index]
  27.                 array[index] = TempValue
  28.                 array2[index] = TempValue2
  29.         reducingindex = reducingindex - 1
  30.  
  31.     return array, array2
  32.  
  33. keys = ["Math", "Biology", "Chemistry", "Physics", "UTS", "Philosophy", "English", "Filipino", "Programming", "Computing", "Arts", "PE", "ASF", "NSTP", "History"]
  34. values = [99,98,97,96,95,94,93,92,91,90,89,88,87,86,85]
  35.  
  36. newKeys, newValues = BubbleSort(keys, values)
  37.  
  38. find = input("Enter subject: ")
  39.  
  40. index = BinarySearch(newKeys, find)
  41.  
  42. print(newValues[index])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top