CLRS で Insertion Sort アルゴを使用していました。どちらが正しい実装かわかりません -
実装 1 :
def Insertion_sort():
list = [3,5,1,7,2,4]
for j in xrange(1,len(list)):
i = j-1
while i>=0 and list[i] > list[j]:
swap(list, i, j)
j = i
i = i-1
実装 2:
def Insertion_sort2():
list = [3,5,1,7,2,4]
for j in range(1,len(list)):
i = j-1;
while i>=0 and list[i]>list[j]:
i = i-1;
swap(list, i+1, j)
ありがとう