stl sort in c++
C++
// 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;
}
sort(arr, arr+n, greater<int>()); // sorts in descending order 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 << i << " ";
}
sort(arr, arr+n); // sorts in ascending order
Also in C++:
- Title
- catalan number calculator
- Category
- C++
- Title
- assegnare valori in c++
- Category
- C++
- Title
- maximum subarray sum in c++
- Category
- C++
- Title
- Merge k sorted linked lists and return it as one sorted list.
- Category
- C++
- Title
- conditional operator in cpp
- Category
- C++
- Title
- queue stl c++
- Category
- C++
- Title
- pop_back
- Category
- C++
- Title
- how to create object in c++
- Category
- C++
- Title
- c++ get type name of object
- Category
- C++
- Title
- log base 10 c+_+
- Category
- C++
- Title
- how to find the number of cycles in a graph C++
- Category
- C++
- Title
- c++ pointers
- Category
- C++
- Title
- How to traverse in a tree iterative C++
- Category
- C++
- Title
- c++ string to stream
- Category
- C++
- Title
- fmod c++
- Category
- C++
- Title
- how to print for limited decimal values in c++
- Category
- C++
- Title
- how to round to nearest whole number unity
- Category
- C++
- Title
- singleton c++
- Category
- C++
- Title
- FInd the element which appears more than n/2 times C++
- Category
- C++
- Title
- how the theam are store in database
- Category
- C++
- Title
- modulo c++
- Category
- C++
- Title
- matrix eigen c++ example
- Category
- C++
- Title
- c++ get length of array
- Category
- C++
- Title
- heap in cpp stl
- Category
- C++
- Title
- removing repeated characters in a string c++
- Category
- C++
- Title
- max in c++
- Category
- C++
- Title
- properties of a set c++
- Category
- C++
- Title
- unsorted array to bst
- Category
- C++
- Title
- char* to int in cpp
- Category
- C++
- Title
- remove element by index from vector c++
- Category
- C++
- Title
- how to execute c++ program in cmd
- Category
- C++
- Title
- maximum possible number atmost k swaps
- Category
- C++
- Title
- cin.ignore
- Category
- C++
- Title
- peak in c++
- Category
- C++
- Title
- how to pass an object by reference in c++
- Category
- C++
- Title
- how to declare a function in c++
- Category
- C++
- Title
- arrow operator c++
- Category
- C++
- Title
- reverse a linked list using recursion
- Category
- C++
- Title
- set of vectors c++
- Category
- C++
- Title
- how to inject a dll into a game c++
- Category
- C++
- Title
- array search c++
- Category
- C++
- Title
- command line options in c++
- Category
- C++
- Title
- c++ stack
- Category
- C++
- Title
- set lower bound c++
- Category
- C++
- Title
- cpp create lambda with recursion
- Category
- C++
- Title
- find in vector in c++
- Category
- C++
- Title
- what is time complexity of min_element()
- Category
- C++
- Title
- double to int c++
- Category
- C++
- Title
- c++ constructor
- Category
- C++
- Title
- #include
- Category
- C++
- Title
- find in string c++
- Category
- C++
- Title
- matrix class in c++
- Category
- C++
- Title
- unordered_map c++ insert
- Category
- C++
- Title
- how to initialize an struct object in c++
- Category
- C++
- Title
- E/flutter (20384): [ERROR:flutter/third_party/txt/src/minikin/FontFamily.cpp(184)] Could not get cmap table size! E/flutter (20384): F/flutter (20384): [FATAL:flutter/third_party/txt/src/minikin/FontCollection.cpp(95)] nTypefaces == 0
- Category
- C++
- Title
- popualte an array c++
- Category
- C++
- Title
- c++ do you not inherit constructor
- Category
- C++
- Title
- primeros numeros primos
- Category
- C++
- Title
- matrix multiplication c++ eigen
- Category
- C++
- Title
- loop through array c++
- Category
- C++
- Title
- remove from unordered_set c++
- Category
- C++
- Title
- C++ and endl
- Category
- C++
- Title
- how to read and write in a file c++
- Category
- C++
- Title
- RLE Encoding/Compression c++
- Category
- C++
- Title
- erase in set
- Category
- C++
- Title
- binary search stl in c++
- Category
- C++
- Title
- string input
- Category
- C++
- Title
- c++ string to int
- Category
- C++
- Title
- pionter in c++
- Category
- C++
- Title
- basic ex of maps in c++
- Category
- C++
- Title
- c++ replace substrings
- Category
- C++
- Title
- c++ reverse vector
- Category
- C++
- Title
- expected initializer before 'isdigit'|
- Category
- C++
- Title
- how to make a switch case statement in c++
- Category
- C++
- Title
- how to format decimal palces in c++
- Category
- C++
- Title
- can you use a return to print a string when referencing an integer c++
- Category
- C++
- Title
- Get handle in C++
- Category
- C++
- Title
- least number of coins to form a sum
- Category
- C++
- Title
- c++ while loop code
- Category
- C++
- Title
- initialize 3d vector c++
- Category
- C++
- Title
- string substr c++
- Category
- C++
- Title
- pairs in c++
- Category
- C++
- Title
- namespace file linking c++
- Category
- C++
- Title
- maximum subarray sum equal with K in c++
- Category
- C++
- Title
- in c, is class uppercase or lowercase
- Category
- C++
- Title
- convert char to string - c++
- Category
- C++
- Title
- power c++
- Category
- C++
- Title
- pass vector by reference c++
- Category
- C++
- Title
- c++ get ascii value of char
- Category
- C++
- Title
- sum of two numbers c++
- Category
- C++
- Title
- c++ unittest in ros
- Category
- C++
- Title
- declaration vs. definition cpp
- Category
- C++
- Title
- c++ argv
- Category
- C++
- Title
- how to make a 2d vector in c++
- Category
- C++
- Title
- dynamic 2d array c++
- Category
- C++
- Title
- c++ function return array
- Category
- C++
- Title
- how to check type in c++
- Category
- C++
- Title
- variadic templates
- Category
- C++
- Title
- substr c++
- Category
- C++
- Title
- namespace c++
- Category
- C++