728x90 CS/Algorithm3 [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. [Algorithm] Merge Sort 특징 안정적인 속도 시간복잡도 O(n log(n)) int*mergeSort(int*_arr, int size){ if(size == 1){ return _arr; } int half = size/2; int*halfArr = new int[half]; for(int i=0; i 2023. 4. 10. [Algorithm]Counting Sort 특징 메모리 사용이 많음 시간복잡도 O(n) #include int countingSort(int*arr, int n); int main(){ int arr[10] = {10, 9, 8, 7, 6, 5,4,3,2,1}; countingSort(arr, 10); for(int i =0; i 2023. 4. 10. 이전 1 다음