프로그래밍 언어에서 정렬은 이러한 데이터를 정렬하기 위해 데이터에 적용되는 기본 기능입니다. 오름차순 또는 내림차순 데이터입니다. C++ 프로그램에는 배열을 정렬하는 std::sort() 함수가 있습니다.
sort(start address, end address)
여기,
Start address => The first address of the element. Last address => The address of the next contiguous location of the last element of the array.
예시 코드
#include <iostream>
#include <algorithm>
using namespace std;
void display(int a[]) {
for(int i = 0; i < 5; ++i)
cout << a[i] << " ";
}
int main() {
int a[5]= {4, 2, 7, 9, 6};
cout << "\n The array before sorting is : ";
display(a);
sort(a, a+5);
cout << "\n\n The array after sorting is : ";
display(a);
return 0;
} 출력
The array before sorting is : 4 2 7 9 6 The array after sorting is : 2 4 6 7 9