'''
Created on 2016年12月9日
@author: jiangxh
'''
#可用内置函数代替
def reverse(l, left, right):
for m in range((right-left)//2):
temp = l[right-1-m]
l[right-1-m] = l[left+m]
l[left+m] = temp
'''
不占额外内存,数组向左移位N
'''
def leftMove1(list, step):
reverse(list, 0, len(list))
reverse(list, 0, len(list)-step)
reverse(list, len(list)-step, len(list))
'''
占用额外内存
'''
def leftMove2(list, step):
l = list[:step]
for m in range(step, len(list)):
list[m-step] = list[m]
list[len(list)-step:] = l
list = [0,1,2,3,4,5,6,7,8,9,10]
step=4
print(list)
leftMove1(list, step)
print(list)
list = [0,1,2,3,4,5,6,7,8,9,10]
print(list)
leftMove2(list, step)
print(list)
转载于:https://www.cnblogs.com/ahua1188/p/6149636.html