c++ sort

// C++ program to demonstrate default behaviour of 
// sort() in 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]); 
  
    sort(arr, arr+n); 
  
    cout << "\nArray after sorting using "
         "default sort is : \n"; 
    for (int i = 0; i < n; ++i) 
        cout << arr[i] << " "; 
  
    return 0; 
} 

3.89
9

                                     int arr[]= {2,3,5,6,1,2,3,6,10,100,200,0,-10};
    int n = sizeof(arr)/sizeof(int);  
    sort(arr,arr+n);

    for(int i: arr)
    {
        cout &lt;&lt; i &lt;&lt; &quot; &quot;;
    }

3.89 (9 Votes)
0
3.5
6
CMG 125 points

                                    #include&lt;bits/stdc++.h&gt;

vector&lt;int&gt; v = { 6,1,4,5,2,3,0};
sort(v.begin() , v.end()); // {0,1,2,3,4,5,6} sorts ascending
sort(v.begin(), v.end(), greater&lt;int&gt;()); // {6,5,4,3,2,1,0} sorts descending

3.5 (6 Votes)
0
4.56
8
PL0 115 points

                                    #include &lt;bits/stdc++.h&gt; 
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 &lt; n; i++){
        cout &lt;&lt; a[i];
    }


    return 0;

}

4.56 (9 Votes)
0
0
6
Lana Kova 135 points

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

0
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
sort array and store result in intger c++ types of sort in c++ STL sort string in c++ using stl sorting function tc in c++ stl C++ array sort method int sorting c++ sort an integer array in c++ array sort in c++ sort array in ascending numbers c++ sorting arr[ in c++ array sort in stl c++ sort array in ascending order sort ann array c++ how sort function works in c++ implement sort in cpp how can you sort array in c++ using stl sort an int array in c++ library function to sort an array in c++ stl sort in c++ by which sort how to use sort func in c++ sort() for array in c++ sort() cpp which sort algorithm does c++ how to use sort function in c++ c++ sort function explained sort() is stl? sort in std c++ sort function code in c++ stl sort array arrange int array in order c++ sort c++ code STL sort c++ how to sort an array in c++ stl define a sort function c++ function sort c++ sort array c+ sort implementation c++ sort array in cpp stl stl sort function use function for sorting arrays c++ string sort stl c++ std sort by sorting integer in c++ stl sort implementation sort algorith stl c++ cpp array sort std::sort in cpp how to make sort function in c++ sort methods for arrays in c++ c++ order array what does stl sort use sorting implementation in c++ sort function library in c++ arry sort in cpp how to use sort stl function how to sort an array in ascending order c++ sort integer array c++ sort method in stl how to use this in sort c++ stl sort cpp reference sort int cpp cpp sort int array sort() in c++ stl sort structure c++ c++ use which sort c++ sorting algorithm std::sort() in C++ sort c++ syntax include sort c++ sort function in array c++ explanation sorting in cpp c++ stl sorting algorithms sort integer array c++ o (n) which sort does stl sort use sorting an array in c++ sort int c++ c++ sorting int array how to include sort c++ c++ sorting array of numbers cpp sort() what is sort function in c++ how to sort a array in cpp sorting in array in c++ C++ sort int array algorithm C++ sort array algorithm c++ sort documentation using std sort c++ declare sort in C++ how to directly sort a array in C++ int arr sort c++ sorting the elements of an array in c++ stl function to sort an array sort int array in c++ sorting methods c++ sort function in c++ for array how to sort array of integers in c++ sorting an integer array in c++ sort() in c++ how to sort in stl int array sort c++ sorting in c++ array how to use the sort function in c++ how to sort a integer in c++ sort array ascending order numbers c++ sort function in cpp algorithm sort of an array c++ sort string c++ stl sorting integer array in c++ how to order an array of integers in c++ sort function in c++ implementation when we use the sort function in c++ which sort is used how to sort an array in c++ example declare function in sort stl sort c++ algorithm how does sort function work in c++ sort int * c++ c++ int sort sort stl in c++ sort with stl sorting stl in c++ sorting in stl sort in stl c++ std sort stl cpp sort std sort in c++ sort an array in c++ using stl sort c++ int sort c++ integer sort array cpp array simple sort C++ sort stl function how to sort array in c++ use algorithm sort function c++ sort() function in c++ sort an simple array cpp sorting function in C++ using stl c++ sort on a array how to sort a array in C++ sort function in c++ algorithm sort function cpp stl array sort std::string sort in cpp how to sort using stl sort algorithm.h sorting a long long int array in c++ sorting logic c++ header file for sort sorting an array using stl write a program to sort an array in c++ c++ sorting an array how to sort array in c++ with for sort header in cpp std::sort for array sort algorithm c++ array sort highest to lowest c++ compare function in sort c++ c++ order array by size algorithm sortc++ c++ sort class sort an array using stl sort by function c++ c++ sort string c++ sort address of array how to use array sort in cpp string array sort c++ how to sort an array in c sort a list of strings in c++ stl Sorted array c++ array sorting algorims c++ array sorting in algorithm library c++ array sorting in c++ inputs taken by user sorting code in c++ cpp std sort reverse sort funtion stl sorting of numbers C++ sort stl first uses gfg how to use sort function in cpp c++ sort algorithm library how to sort array elements in c++ sort class c++ c++ built in sorting algorithms c++ built in sort sort using c++ function to sort an array in cpp sort in array c++ compare functiokn in stl sort sort(a,a+n,greater&lt;int&gt;()); stl library for sorting sort() in c sort in c++ using stl how to use comp function in sort in stl c++ selection sort c++ sort array std sort function header file for sort in c++ sort c++ stl with comparotor c++ function array sort stl c++ sort time complexity inbuilt function to sort array in c++ best array sorting algorithm c++ sorting algo in c++ bubble sort c++ how to write array sort function c++ std sort sort std c++ sort c++ function sort in c++ algorithm.h sorting an array in c++ with inbuilt sort function sort in c++ using function sort()in c++ definition of c++ std::sort sort an int array in cpp sort array c++ library array sorting algorithm c++ std::sort in c comparator function for sort for descending order cpp stl sort arra cpp sort algorithm sort a string in c++ how to sort an integer in ascending order using C++ function how to sort an integer C++ function sorting algorithms in cpp array sort library c++ sort array by size c++ sort array +/c+ sort array ++ sort an int array c++ sorting of array in c++ code sport an array c++ library for sort function in c++ c++ array sort algorithm c++ sort algorithm function sort function use sorting algorithms using stl library sort in c++ function sorting part of array cpp sorting string in cpp inbuilt sort function in c++ order crossover c++ standard lib to sort array in c++ predefined sorting array in c++ std::sorting arr in c++ array sort in cpp sorting array using stl how to sort a stack in c++ sort string in c++ sorting.cpp inbuilt sort in c++ code sort an array in ascending order c++ how to sort a structure array in c++ sort set c++ is there any sort function in array in c++ inbuilt c++ function to sort an array sort std in c++ std srot how c std sort works c++ include sorting c++ include sort is sort a built in function in c++ sort string c++ sort(a+p,a+q) c++ custom comparator sort c++ stl sort condition std vector sort stl c++ sort stl to sort an array in C c+ sorting c++ sort array library algorithm sort c++ comparison function sort c++ c++ sort array ascending c++ program to sort array in ascending order sort with user defined comparator c++ c++ sort compare function vector functions c++ sort sorting sytems c++ algorithm sort c++ iterator c++ sorting arrays sort function header file void Sort c++ how can sort integer in array in c++ how to sort elements in nascending order in array in c++ sort using some function in c++ how to override default sort method cpp vector sort algorithm c++ c++ sorted how to sort array in descending order in c++ order array c++ sorting a vector c++ c++ algorithm sorting how to sort array in increasing order in c++ sorting of array in c++ program sorting c++ stl for sort stdlib c++ sort() c++ function for sortin sort array c++ c++ algorithm library sort stl sort begin c++ how to sort an array c++ writing function to sort algorithm c++ buildin sort function arrays.sort in c++ sort st c++ c++ sort function array C algorithm sort stl sorting algorithms sort int array c++ how to sort a array c+= sorting stl sort stl example sort( greater&lt;int&gt;) c++ sort c++ array what is int sort in c++ array sort in function in c++ sort() c++ array inbuild sort function sort in algorithm c++ sort array in c++ with stl sort stl arrange array in ascending order c++ c++ sort compare function' cpp import sort how to sort all array in c++ sort an arr in c++ self defined in sort in c++ sorte c+= example sorting function c++ stl sort shorting an array in cpp sort(all(vals))c++ bool compare function c++ sort descending c++ stl sorting arra y in c++ sort c++ manual writing comparator for sort in c++ sort function in c++ uses which algorithm how to use inbuilt sort function in c++ sort a segment of an array in c++ using stl is the any function to sort an array in c++ c++ sort vector custom function sort array c++ ascending how to write compare function for sort in c++ sort documentation cpp in-order function c++ std sort c++ sorting c++ custom sort comparator c++ sorts c++ arrange array in ascending order in c++ using sorting sorting library in c++ c++ sort algorithm sort array from least to greatesr c++ function sort array function in c++ how to use sort in Cpp c++ sort exaple c++ can an array be sorted sort array using sort function c++ how to sort an array using stl sort c++ decreasing sort function in c++ descending sort comparator c++ write own bool comp in sort c++ c++ sort comparator function example c++ sort compare function example what is greater&lt;int&gt; in sort function of c++ sorting array in c++ code compare function of sort in c++ how to sort descending in c++ function to sort an array in c++ c++ custom sort sorting of array in cpp header file for sort function in c++ sort function in descending order c++ sort stl .sort in c++ c++ code to sort an array in ascending order using sort algorithm c++ code to sort an array in ascending order c++ sort an array greater to smaller sort c++ how to change the sort in c++ sort header c++ defining your own sort c++ sort in c++; array sort c++ function sort greater int c++ sort array of int c++ sort in increasing using comparator c++ sort a integer in c++ sample sort c++ sort(budget,budget+n); means in c++ ascending order program in c++ how to sort an array in c ++ Arrays.sort() c++ sort in cpp std sort algorithm c++ sorting in c++ stl reverse sorting in c++ sort based on comp c++ sort with respect to a parameter in c++ sorting a in c++ c++ inbuilt sorting function algorithms custom comparator c++ comparator in c++ gfg comparator class in c++ gfg comparator sort c++ sort an array cpp import in c++ for sort sort inbuilt function in c++ comparator c++ is there any direct sort function in strings in c++ comp function c++ sort() c++ doc sorting array in c++ string sort comparator c++ c++ array sort sorting of array in c++ sort function in stl c++ sorting array sort function stl c++ sort function for array in c++ soring in cpp sort in decreasing order in c++ arry in accending order in c++ code to sort an array in c++ sorting comparartor function ([]) reverse sort cpp sort c++ comparator sort and array in c++ sort in descending order c++ sort library in c++ c++ predefined sort function array sort array c++ function sort a array cpp std sort c++ string sort function in c++\ standard sort c++ hoe to sort an array in c++ sort a array c++ std::sort c++ sorting an array using sort function in c++ how to use sort in c++ sort c++\ built in sort function in c++ sort given array c++ sort c++ custom comparator sort int vector c++ compator to sort strings cpp sorting inorder C++ sorting inplace STL C++ sort an array c++ ascending inbuilt function to sort a vector in c++ how to sort an array from highest to lowest c++ decending sort in c++ sorting an array cpp c++ module to sort an array c++ comparator c++ sort() array sorting function in c++ c++ sort increasing order how does sort work c++ sort method cpp sort function for an array c++ sort method in c++ how to place an element in sorted array in C++ using STL sort with comparator c++ sort vector in c++ cutom comparator c++ stl how to sort in c++ how to customize sort stl in cpp shortcut to print sorted array in c c++ sorting a predefined array number of operations of sorting in c++ order of sorting in c++ sorting array elements by stl c++ sort a given array using c++ compare function for sort in c++ sort(arr ,arr+n) by default uses which type of sort function sort array cpp function sort c++ library sort array stl sort stl c++ sorting an array in c++ program modifing sort condittion in c++ stl sort an array in ascending order cpp function of sort in c++ sorting an array stl sort array function c++ sort function in algorithm c++ sort decreasing c++ sort array in c/c++ stl in c++ sort sort in descending order in c++ include for sort c++ comparator function for sort in c++ sort using key stl c++ sort with comparator cpp using sort function in c++ for competitve programming sort array in ascending order c++ sort with function c++ how to sort elements in array in c++ sort fn in c++ c++ sorting library how sort array in c++ c++ all stl sorts function to sort array in c++ sort an array in c++ stl cpp comparator how to sort by second value where first must be small in cpp sorting array in cpp c++ sort array maintain order in custom sort c++ sorting with comparator cpp compare function in c++ sorting sort array in c++ using sort custom compare function in sort c++ custom sort c++ c++ sorrt std::sort array sort an array in cpp USING SORT IN C++ sort numbers in descending order c++ how to sort in cpp how to arrange elements of array in ascending order in c++ comparator in c++ use std sort in c++ compare funciton in sort c++ sort array numbers c++ STL sort to sort a vector sort in c++ descending order sort cpp stl vector.sort sorting numbers c++ comp in sort c++ C++ library sorting sorting arrays in c++ wit libraries sort array by increasing or decreasing value cpp std:;sort c++ first sort algorithm c++ cmp sort stl sort function sort array in c++ algorithm array.sort in c++ sort function in c++ stl sorting an array in cpp c++ vector.sort what is the sort algorithm in the stl sort std::sort operator&lt; c++ sort include array sort cpp sort function in bits/stdc++.h sort comparator cpp sort stl cpp cmp function in cpp for sort how does the sort compare function actually work in cpp sort stl c++ is which sort simple c++ sorting program .begin .end sorting c++ how to sort an array by value in c+= how to return sorted array in cpp Arrange students c++ sort vector c++ sorting c++ stl cpp sort function stl sort in c++ c++ sort vector sorting arrays in c++ sort function c++ documentation array sort c++ how to sort array using stl how to sort any anrray in c++ array sort function in c++ c++ how to sort array sorting the array in c++ how to sort int array c++ how to sort array c++ stl for sorting array sort array using stl sort array in cpp sort an array of integers c++ c++ sort vector header file c++ std::sort sort in c++ library sorting in function c++ sort c++ stl array sorting in c++ cpp sort sort array in c++ how to sort numbers in c++ array c++ acending sort algo sort method c++ sort an array stl how to sort an interger array in c++ sort an array in c++ cpp sort array sort an array C++ h sort c++ sort a c++ array .sort() c++ sorting array inc++ sort ing in c++ how to sort an array c++ sorting in c++ c++ int array sort c++ arrray sort sort in c++ c++ sort library sort function in c++ how to sort elements in array c++ sort function c++ how to sort an array in cpp c++ sort int array sorting header file in c++ what header is sort in c++ sorting an array c++ sort c++ comp example sort algorithm c++ c++ algorithm sort sort() C++ how to sort an array in c++ with a function sort cpp sort array c++ example sort library c++ c++ sort function how to sort an array in c++ how to sort array in c++ c++ sort array of ints c++ vector sort c++ sorting sort c++ c++ stl sort c++ sort
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source