sort function in array code example
Example 1: stl for sorting IN C++
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main()
{
int arr[] = {1, 5, 8, 9, 6, 7, 3, 4, 2, 0};
int n = sizeof(arr)/sizeof(arr[0]);
sort(arr, arr+n);
reverse(arr,arr+n);
sort(arr, arr + n, greater<int>());
}
Example 2: sort javascript array
var points = [40, 100, 1, 5, 25, 10];
points.sort((a,b) => a-b)
Example 3: javascript sort function
var points = [40, 100, 1, 5, 25, 10];
points.sort((a,b) => a-b)