Python 쉘정렬 구현

Jmnote (토론 | 기여)님의 2018년 8월 28일 (화) 11:36 판 (→‎같이 보기)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요[ | ]

Python 쉘정렬 구현
파이썬 쉘정렬 구현
def shell_sort(a):
    size = len(a)
    gap = size//2
    while gap>0:
        for i in range(gap,size):
            temp=a[i]
            j=i
            while j>=gap and a[j-gap]>temp:
                a[j]=a[j-gap]
                j-=gap
            a[j]=temp
        gap//=2
arr = [9,1,22,4,0,-1,1,22,100,10]
shell_sort(arr)
print(arr)
# [-1, 0, 1, 1, 4, 9, 10, 22, 22, 100]

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}