Advertisement
Guest User

lab 7

a guest
Nov 20th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. def bubble_sort(tab):
  2. while True:
  3. zamiana = False
  4. for i in range(len(tab) - 1):
  5. if tab[i] > tab[i + 1]:
  6. tmp = tab[i]
  7. tab[i] = tab[i + 1]
  8. tab[i + 1] = tmp
  9. zamiana = True
  10.  
  11. if not zamiana:
  12. break
  13. return tab
  14.  
  15.  
  16. def wyszukiwanie_binarne(a, b):
  17. a = bubble_sort(a)
  18. left = 0
  19. right = len(a) - 1
  20.  
  21. while left < right:
  22. middle = (left + right) // 2
  23. if a[middle] < b:
  24. left = middle + 1
  25. else:
  26. right = middle
  27.  
  28. if a[right] == b:
  29. return True
  30. else:
  31. return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement