Answers for "comparator in sort c++"

C++
12

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
  }
Posted by: Guest on October-18-2020
0

comparator in sort c++

bool com_fun(int a,int b){
	if(a<b) return true;
	else return false;
}

sort(arr,arr+n.com_fun);
Posted by: Guest on October-25-2021
0

sort inbuilt function in c++

#include <bits/stdc++.h> 
using namespace std; 

#define size(arr) sizeof(arr)/sizeof(arr[0]);


int main(){

    int a[5] = {5, 2, 6,3 ,5};
    int n = size(a);
    sort((a), a + n);
    for(int i = 0; i < n; i++){
        cout << a[i];
    }


    return 0;

}
Posted by: Guest on August-11-2020

Code answers related to "comparator in sort c++"

Browse Popular Code Answers by Language