प्रोग्रामिंग भाषा में, छँटाई एक बुनियादी कार्य है जो इन डेटा को व्यवस्थित करने के लिए डेटा पर लागू होता है जो आरोही या अवरोही डेटा है। 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