신규 블로그를 만들었습니다!

2020년 이후부터는 아래 블로그에서 활동합니다.

댓글로 질문 주셔도 확인하기 어려울 수 있습니다.

>> https://bluemiv.tistory.com/
package sort;
 
public class QuickSort {
 
    public static void quick_sort(int[] map, int left, int right) {
        int pivot = map[(right + left) / 2];
        System.out.println("pivot : " + pivot);
        int l = left;
        int r = right;
 
        while (l < r) {
            // pivot 보다 큰 숫자가 나올때까지
            while (map[l] < pivot) {
                l++;
            }
            // pivot 보다 작은 숫자가 나올때까지
            while (pivot < map[r]) {
                r--;
            }
 
            // 서로 스왑
            if (l <= r) {
                int tmp = map[l];
                map[l] = map[r];
                map[r] = tmp;
                l++;
                r--;
            }
        }
 
        // 왼쪽 실행
        if (left < r) {
            quick_sort(map, left, r);
        }
 
        // 오른쪽 실행
        if (l < right) {
            quick_sort(map, l, right);
        }
    }
 
    public static void main(String[] args) {
        int[] map = { 10, 4, 7, 2, 6, 9, 3, 6, 2, 4, 8 };
        quick_sort(map, 0, map.length - 1);
 
        for (int i = 0; i < map.length; i++) {
            System.out.print(map[i] + " ");
        }
    }
 
}​

 

 

 

  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기