1// C++ program to demonstrate default behaviour of
2// sort() in STL.
3#include <bits/stdc++.h>
4using namespace std;
5
6int main()
7{
8 int arr[] = {1, 5, 8, 9, 6, 7, 3, 4, 2, 0};
9 int n = sizeof(arr)/sizeof(arr[0]);
10
11 sort(arr, arr+n);
12
13 cout << "\nArray after sorting using "
14 "default sort is : \n";
15 for (int i = 0; i < n; ++i)
16 cout << arr[i] << " ";
17
18 return 0;
19}
1#include <bits/stdc++.h>
2using namespace std;
3
4#define size(arr) sizeof(arr)/sizeof(arr[0]);
5
6
7int main(){
8
9 int a[5] = {5, 2, 6,3 ,5};
10 int n = size(a);
11 sort((a), a + n);
12 for(int i = 0; i < n; i++){
13 cout << a[i];
14 }
15
16
17 return 0;
18
19}
20
1sort(arr, arr+length); //increase
2sort(arr, arr+length, greater<int>()); //decrease
1#include <algorithm>
2#include <iostream>
3#include <array>
4using namespace std;
5
6int main() {
7 array<int, 5> arraysort{ 4,2,3,5,1 };
8 sort(arraysort.begin(), arraysort.end());
9 for (int i = 0; i < arraysort.size(); i++) {
10 cout << arraysort[i] << " ";
11 }
12 return 0;
13}
1#include <iostream>
22 #include <array>
33 #include <string>
44 #include <algorithm>
55
66 using namespace std;
77
88 int main(){
99 array<string, 4> colours = {"blue", "black", "red", "green"};
1010 for (string colour : colours){
1111 cout << colour << ' ';
1212 }
1313 cout << endl;
1414 sort(colours.begin(), colours.end());
1515 for (string colour : colours){
1616 cout << colour << ' ';
1717 }
1818 return 0;
1919 }
2066
2120
2221 /*
2322 Output:
2423 blue black red green
2524 black blue green red
2625 */