#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
'공부 > Code Cata' 카테고리의 다른 글
3진법 뒤집기 (1) | 2024.12.27 |
---|---|
행렬의 덧셈(함수 내 배열 크기와 함께 초기화) (0) | 2024.12.26 |
std::sqrt (0) | 2024.12.22 |
약수의 개수가 홀수인가? (0) | 2024.12.22 |
std::inner_product(내적 계산) (0) | 2024.12.22 |