what is sort function in c++ code example
Example 1: C++ sorting array
#include
using namespace std;
#define MAX 100
int main()
{
//array declaration
int arr[MAX];
int n,i,j;
int temp;
//read total number of elements to read
cout<<"Enter total number of elements to read: ";
cin>>n;
//check bound
if(n<0 || n>MAX)
{
cout<<"Input valid range!!!"<>arr[i];
}
//print input elements
cout<<"Unsorted Array elements:"<arr[j])
{
temp =arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
//print sorted array elements
cout<<"Sorted (Ascending Order) Array elements:"<
Example 2: sort c++
sort(arr, arr+length); //increase
sort(arr, arr+length, greater()); //decrease
Example 3: c++ sort
int arr[]= {2,3,5,6,1,2,3,6,10,100,200,0,-10};
int n = sizeof(arr)/sizeof(int);
sort(arr,arr+n);
for(int i: arr)
{
cout << i << " ";
}