Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. def insert_log(lst, item):
  2. placed = True
  3.  
  4. low = 0
  5. top = len(lst)
  6. mid = top // 2
  7.  
  8. while placed:
  9. index = lst[mid]
  10.  
  11. if index == item:
  12. placed = False
  13. lst.insert(index, item)
  14.  
  15. if lst[mid] > item > lst[mid-1]:
  16.  
  17. placed = False
  18. lst.insert(mid, item)
  19.  
  20. elif index > item:
  21. top = mid
  22. mid = (low + mid) // 2
  23.  
  24. elif index < item:
  25. low = mid
  26. mid = low + ((top - low) // 2)
  27. return lst
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement