Python 퀵정렬 구현

Jmnote (토론 | 기여)님의 2020년 6월 28일 (일) 19:57 판 (→‎개요)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요[ | ]

Python 퀵정렬 구현
파이썬 퀵정렬 구현
def quick_sort(a, L=0, R=-1):
    if R==-1: R=len(a)-1
    pivot=a[L]
    left=L
    right=R
    while left<right:
        while a[right]>=pivot and left<right: right-=1
        if left<right: a[left]=a[right]
        while a[left]<=pivot and left<right: left+=1
        if left>=right: break
        a[right]=a[left]
        right-=1
    a[left]=pivot
    if left>L: quick_sort(a, L, left-1)
    if left<R: quick_sort(a, left+1, R)

arr = [9,1,22,4,0,-1,1,22,100,10]
quick_sort(arr)
print( arr )

2 같이 보기[ | ]

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