728x90 quicksort1 [Algorithm] Quick Sort 특징 Merge 나 Heap Sort 보다 빠름 시간복잡도 O(n log(n)) 최악의 경우가 O(n^2) #include #include using namespace std; void SwapInt(int& a, int& b) { int temp = a; a = b; b = temp; } void QuickSort(vector& arr) { //배열의 크기가 1이면 정렬할게 없으므로 반환 if (arr.size() arr[pivot] && arr[right] < arr[pivot]) {//left 가 pivot보다 크고, right 가 pivot 보다 작으면 Swap SwapInt(arr[left], arr[right]); left++;//Swap 후 각각 좌로 우로 옮겨줌 right--; } } Sw.. 2023. 4. 23. 이전 1 다음