전체 글332 삽입 정렬(Insertion Sort) 시간복잡도 O(n^2) // 선택된 수를 정렬된 위치 사이에 void insertionSort(int arr[], int n) { for (int i = 0; i = 0; j--) { if (arr[j] > key) arr[j + 1] = arr[j]; else break; } arr[j + 1] = key; // 찾은 위치에 삽입 } cout 2019. 6. 18. 선택 정렬(Selection Sort) 시간복잡도 O(n^2) // 가장 작은 수를 선택하여 좌측으로 void selectionSort(int arr[], int n) { int min; // 최소값 int minIndex; // 최소값 인덱스 for (int i = 0; i 2019. 6. 18. 버블 정렬(Bubble Sort) 시간복잡도 O(n^2) // 인접한 두 수를 비교하여 큰 수를 뒤로 보낸다. void bubbleSort(int arr[], int n) { int temp; for (int i = 0; i 2019. 6. 18. 정렬(Sort) 종류 선택 정렬(Selection Sort) O(n^2) 버블 정렬(Bubble Sort) - 실제론 잘 쓰이지 않음 O(n^2) 삽입 정렬(Insertion Sort) O(n^2) 퀵 정렬(Quick Sort) O(n log n) - average O(n^2) - worst 병합 정렬(Merge Sort) O(n log n) 힙 정렬(Heap Sort) O(n log n) 기수 정렬(Radix Sort) O(n) 계수 정렬(Counting Sort) O(n) 2019. 6. 18. STL map ;map 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 unordered_map umap; umap.insert({"test1", 1}); umap.emplace("test5", 5); umap["test1"] = 4; for(auto element : umap){ cout 2019. 6. 17. STL algorithmn ;find #include vector v; v.push_back(1); v.push_back(2); vector::iterator iter; iter = find(v.begin(), v.end(), 1); if (iter != v.end()) cout 2019. 6. 13. 이전 1 ··· 52 53 54 55 56 다음