공부/Code Cata

Quick Sort

동그래님 2024. 12. 23. 20:53

 

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

string solution(string s) {
    sort(s.begin(), s.end(), greater<>());
    
    return s;
}

이와 같이 <algorithm>헤더의 sort함수를 사용해 쉽게 값을 구할 수 있었지만, 내부 구현이 어떻게 되는지 궁금하여 정렬 알고리즘에 대해 공부해봤다. 

 

정렬 알고리즘에는 퀵정렬, 버블정렬, 삽입정렬, 선택정렬 등 여러 정렬 방법이 있는데 그 중, 퀵정렬에 대해 공부하였다.

 

Quick sort 정렬 알고리즘: https://dong-grae.tistory.com/53

 

Quick Sort 정렬 알고리즘

Quick Sort#include #include #include using namespace std;// 기준점 Pivot 보다 작으면 왼쪽으로, 크면 오른쪽으로 swap하는 분할 함수int Partition(string& str, int Left, int Right){ char Pivot = str[Right]; // 마지막 요소를 기

dong-grae.tistory.com