Search
 
SCRIPT & CODE EXAMPLE
 

CPP

stl for sorting IN C++


// STL IN C++ FOR SORING
#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);  // ASCENDING SORT
    reverse(arr,arr+n);   //REVERESE ARRAY 
    sort(arr, arr + n, greater<int>());// DESCENDING SORT
  } 
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 :: what is time complexity of min_element() 
Cpp :: extern __shared__ memory 
Cpp :: c++ compare strings ignore case 
Cpp :: cpp random in range 
Cpp :: c++ uniform_real_distribution get same result 
Cpp :: cout hello world 
Cpp :: c++ remove whitespace from string and keep the same size 
Cpp :: xmake set exe name 
Cpp :: casting pointer (int to char*) in c++ 
Cpp :: qlabel set text color 
Cpp :: c++ find sum of vector 
Cpp :: convert vector into array c++ 
Cpp :: macro c++ 
Cpp :: hello world C++, C plus plus hello world 
Cpp :: how to hide the c++ console 
Cpp :: initialize 2d array c++ memset 
Cpp :: c++ print number not in scientific notation 
Cpp :: convert int to string c++ 
Cpp :: c++ ros publisher 
Cpp :: how to read a comma delimited file into an array c++ 
Cpp :: google pdf iframe viwer 
Cpp :: change to lowercase in notepad++ 
Cpp :: sort stl 
Cpp :: string to vector char c++ 
Cpp :: how print fload wiht 2 decimal in c++ 
Cpp :: min heap and max heap using priority queue 
Cpp :: c++ segmented sieve 
Cpp :: when was c++ created 
Cpp :: c vs c++ 
Cpp :: file c++ 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =