Algorithm Problems

[정올] [Python] 3518번 퀵정렬

WakaraNai 2021. 4. 3. 20:43
728x90
반응형

www.jungol.co.kr/bbs/board.php?bo_table=pbank&wr_id=2858&sca=30

 

JUNGOL

 

www.jungol.co.kr

def quicksort(a,low,high):
    if low<high:
        pivot = a[high]
        i = low-1
        for j in range(low,high):
           if a[j] < pivot:
               i+=1
               a[i],a[j] = a[j], a[i]
        i+=1
        a[i],a[high] = a[high], a[i]
        for num in a:
            print(num,end=" ")
        print()

        quicksort(a,low,i-1)
        quicksort(a,i+1,high)



n=int(input())
nums = list(map(int, input().split()))
quicksort(nums,0,n-1)
728x90
반응형