1 개요[ | ]
- Python 퀵정렬 구현
- 파이썬 퀵정렬 구현
Python
CPU
0.0s
MEM
8M
0.0s
Copy
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 )
[-1, 0, 1, 1, 4, 9, 10, 22, 22, 100]
2 같이 보기[ | ]
편집자 Jmnote
로그인하시면 댓글을 쓸 수 있습니다.