Search
 
SCRIPT & CODE EXAMPLE
 

CPP

sort stl

1) When using vector:
	sort(arr.begin(), arr.end());

2) When using array:
	sort(arr, arr+n);
	sort(arr, arr+n, greater<int>()); //sorts in descending
Comment

stl sort in c++

sort(arr, arr+n); // sorts in ascending order
Comment

stl sort in c++

sort(arr, arr+n, greater<int>()); // sorts in descending order
Comment

sort c++ stl

#include <bits/stdc++.h>
using namespace std;
  
int main()
{
    int arr[] = { 1, 5, 8, 9, 6, 7, 3, 4, 2, 0 };
    int n = sizeof(arr) / sizeof(arr[0]);
  
    /*Here we take two parameters, the beginning of the
    array and the length n upto which we want the array to
    be sorted*/
    sort(arr, arr + n);
  
    cout << "
Array after sorting using "
            "default sort is : 
";
    for (int i = 0; i < n; ++i)
        cout << arr[i] << " ";
  
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ initialize array 1 to n 
Cpp :: c++ call by value vs call by reference 
Cpp :: cpp unions 
Cpp :: c++ sort vector 
Cpp :: string vector c++ 
Cpp :: string to vector char c++ 
Cpp :: c++ return multiple values 
Cpp :: c++ iterate map 
Cpp :: how print fload wiht 2 decimal in c++ 
Cpp :: ue4 c++ enumaeration 
Cpp :: file open cpp 
Cpp :: string to long integer c++ 
Cpp :: memset in c++ 
Cpp :: not in c++ 
Cpp :: udo apt install dotnet-sdk-5 
Cpp :: remove element from array c++ 
Cpp :: c vs c++ 
Cpp :: check if character in string c++ 
Cpp :: calloc c++ 
Cpp :: c++ remove text file 
Cpp :: checking if a string has only letters cpp 
Cpp :: std::iomanip c++ 
Cpp :: sort a vector c++ 
Cpp :: remove specific element from vector c++ 
Cpp :: how do you wait in C++ 
Cpp :: how to add external library in clion 
Cpp :: integer to char c++ 
Cpp :: cpp class constructor 
Cpp :: Disabling console exit button c++ 
Cpp :: C++ Infinite while loop 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =