Created
October 1, 2016 22:33
-
-
Save alexeytal/498fb10ab28c57a8183a18f0464d0ea1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Дан список положительных и отрицательных чисел. | |
Переместить все положительные числа в левую часть | |
списка с сохранением порядка положительных и | |
отрицательных чисел в списке. Все манипуляции можно | |
производить только с исходным списком, дополнительные | |
списки использовать нельзя, удалять элементы из списка | |
тоже запрещено. | |
""" | |
l=[-1,-2,5,6,7,-3,4,5,-3,0,12,-56,-20] | |
for i in reversed(range(len(l)-1)): | |
if l[i]<0: | |
for j in range(i,len(l)-1): | |
if l[j+1]>=0: | |
buf=l[j] | |
l[j]=l[j+1] | |
l[j+1]=buf | |
print(l) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment