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

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 :: define for loop c++ 
Cpp :: How To Calculate 1+1 in c++ 
Cpp :: c to c++ code converter 
Cpp :: long, long long 32 bit or 8 bit in c++ 
Cpp :: how to make a defaule conrstrocr in c++ classes 
Cpp :: c++ text between substrings 
Cpp :: properties of loop in c++ and how it works 
Cpp :: how to change the icon of an exe in c++ 
Cpp :: check whether kth bit is 1 
Cpp :: c++ require keyword 
Cpp :: case 1 or 2 c++ 
Cpp :: How to execute a command and get return code stdout and stderr of command in C++ 
Cpp :: file transfer socat 
Cpp :: delete[] cpp 
Cpp :: Catcoder mars rover solution in c++ 
Cpp :: how to compile with libstdc++ fedora 
Cpp :: c++ insertion in astack 
Cpp :: free pair c++ 
Cpp :: deifine an object in C++ 
Cpp :: txt auslesen c++ 
Cpp :: cpp practice questions 
Cpp :: fasdf 
Cpp :: how to show c++ binary files in sublime text 
Cpp :: glm multiply vector by scalar 
Cpp :: How to write string in lpcstr in c++ 
Cpp :: 1491. Average Salary Excluding the Minimum and Maximum Salary leetcode solution in c++ 
Cpp :: cpp full form 
Cpp :: sort 3 numbers using swap cpp 
Cpp :: CREDSCORE codechef solution 
Cpp :: std::string(size_t , char ) constructor: 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =