Skip to content

Instantly share code, notes, and snippets.

@rolisz
Created February 4, 2012 18:53
Show Gist options
  • Save rolisz/1739458 to your computer and use it in GitHub Desktop.
Save rolisz/1739458 to your computer and use it in GitHub Desktop.
Rezolvare problema 10 examen FP
def insert(list,x):
low = 0
high = len(list) - 1
i = (low+high)//2
while low < high and not (list[i] <= x and list[i+1] > x):
if list[i] < x:
low = i + 1
i = (low+high)//2
else:
high = i - 1
i = (low+high)//2
if high == 0:
i = -1
if low == len(list) - 1:
i = len(list)
list.insert(i+1,x)
return list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment