Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def bubble_sort(tab):
- while True:
- zamiana = False
- for i in range(len(tab) - 1):
- if tab[i] > tab[i + 1]:
- tmp = tab[i]
- tab[i] = tab[i + 1]
- tab[i + 1] = tmp
- zamiana = True
- if not zamiana:
- break
- return tab
- def wyszukiwanie_binarne(a, b):
- a = bubble_sort(a)
- left = 0
- right = len(a) - 1
- while left < right:
- middle = (left + right) // 2
- if a[middle] < b:
- left = middle + 1
- else:
- right = middle
- if a[right] == b:
- return True
- else:
- return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement