c++ sort
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); // sorts in ascending 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 << " ";
}
// A C++ program to sort vector using
// our own comparator
#include <bits/stdc++.h>
using namespace std;
// An interval has start time and end time
struct Interval {
int start, end;
};
// Compares two intervals according to staring times.
bool compareInterval(Interval i1, Interval i2)
{
return (i1.start < i2.start);
}
int main()
{
vector<Interval> v { { 6, 8 }, { 1, 9 }, { 2, 4 }, { 4, 7 } };
// sort the intervals in increasing order of
// start time
sort(v.begin(), v.end(), compareInterval);
cout << "Intervals sorted by start time : \n";
for (auto x : v)
cout << "[" << x.start << ", " << x.end << "] ";
return 0;
}
// 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;
} #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;
}
Also in C++:
- Title
- how read a shader from another file c++
- Category
- C++
- Title
- c++ while true loop
- Category
- C++
- Title
- ceil c++;
- Category
- C++
- Title
- initialize array c++
- Category
- C++
- Title
- substitution failure is not an error
- Category
- C++
- Title
- c++ random numbers
- Category
- C++
- Title
- c++ char define
- Category
- C++
- Title
- registering a new QML type
- Category
- C++
- Title
- deque c++
- Category
- C++
- Title
- how to iterate over unordered_map c++
- Category
- C++
- Title
- arduino falling edge
- Category
- C++
- Title
- initialize map c++
- Category
- C++
- Title
- c++ remove item from list
- Category
- C++
- Title
- pop_back
- Category
- C++
- Title
- never gonna give you up lyrics
- Category
- C++
- Title
- lambda operator in c++
- Category
- C++
- Title
- prefix sum array
- Category
- C++
- Title
- How to check if a triangular cycle exists in a graph
- Category
- C++
- Title
- count a character in a string c++
- Category
- C++
- Title
- how to load from files C++
- Category
- C++
- Title
- shortest path with bfs in c++
- Category
- C++
- Title
- char vector to string c++
- Category
- C++
- Title
- placement new c++
- Category
- C++
- Title
- convert string to stream c++
- Category
- C++
- Title
- unordered_set c++
- Category
- C++
- Title
- how to make a switch case statement in c++
- Category
- C++
- Title
- screen record ios simulator
- Category
- C++
- Title
- how to append one vector to another c++
- Category
- C++
- Title
- nearest integer rounding in c++
- Category
- C++
- Title
- c++ get length of array
- Category
- C++
- Title
- how to measure program run time in c++
- Category
- C++
- Title
- object reference not set to an instance of an object c#
- Category
- C++
- Title
- log base e synthax c++
- Category
- C++
- Title
- find_if c++
- Category
- C++
- Title
- strchr function in c++
- Category
- C++
- Title
- modular exponentiation c++
- Category
- C++
- Title
- how do you add two random numbers in c++
- Category
- C++
- Title
- file objects in c++
- Category
- C++
- Title
- cut by delimiter c++
- Category
- C++
- Title
- c++ switch case statement
- Category
- C++
- Title
- C++ remove element from set
- Category
- C++
- Title
- print type cpp
- Category
- C++
- Title
- min and max heap in cpp
- Category
- C++
- Title
- substr c++
- Category
- C++
- Title
- switch c++
- Category
- C++
- Title
- how to swap string characters in c++
- Category
- C++
- Title
- C++ Syntax
- Category
- C++
- Title
- c++ pointers
- Category
- C++
- Title
- c++ method name
- Category
- C++
- Title
- c++ class constructor
- Category
- C++
- Title
- c++ compare char
- Category
- C++
- Title
- c++ public inheritance not getting protected
- Category
- C++
- Title
- cube mapping sdl
- Category
- C++
- Title
- monotonic deque
- Category
- C++
- Title
- Get handle in C++
- Category
- C++
- Title
- how to find the mode of a vector c++
- Category
- C++
- Title
- how to execute c++ program in cmd
- Category
- C++
- Title
- how to run c++ file mingw cmd
- Category
- C++
- Title
- how to find the number of cycles in a graph C++
- Category
- C++
- Title
- iterar un map c++
- Category
- C++
- Title
- pair c++
- Category
- C++
- Title
- gcd in c++
- Category
- C++
- Title
- how to ensure the user inouts a int and not anything else c++
- Category
- C++
- Title
- c++ class inheritance
- Category
- C++
- Title
- c++ constructor
- Category
- C++
- Title
- cloud hosting
- Category
- C++
- Title
- maximum possible number atmost k swaps
- Category
- C++
- Title
- string to number in c++
- Category
- C++
- Title
- how to read a comma delimited file into an array c++
- Category
- C++
- Title
- c++ comment
- Category
- C++
- Title
- chess perft 5
- Category
- C++
- Title
- inserting an element in an set c++
- Category
- C++
- Title
- iterative preorder traversal
- Category
- C++
- Title
- c++ how to return an empty vector
- Category
- C++
- Title
- sum of integer in array c++
- Category
- C++
- Title
- how to sort vector in c++
- Category
- C++
- Title
- function template
- Category
- C++
- Title
- sum of two numbers c++
- Category
- C++
- Title
- what is iterator in c++?
- Category
- C++
- Title
- vector stl c++
- Category
- C++
- Title
- c++ function to find length of array
- Category
- C++
- Title
- Combination Sum
- Category
- C++
- Title
- new class * [] c++
- Category
- C++
- Title
- c++ ternary operator
- Category
- C++
- Title
- cannot jump from switch statement to this case label c++
- Category
- C++
- Title
- C++ w3schools
- Category
- C++
- Title
- unordered_set in c++ and ordered set diff
- Category
- C++
- Title
- change int to string cpp
- Category
- C++
- Title
- variadic templates
- Category
- C++
- Title
- generate random double c++
- Category
- C++
- Title
- call by reference c++ example
- Category
- C++
- Title
- minmax_element c++
- Category
- C++
- Title
- c++ clear console
- Category
- C++
- Title
- min coin change problem dp
- Category
- C++
- Title
- c++ for loop syntax
- Category
- C++
- Title
- set precision in c++
- Category
- C++
- Title
- length of string in c++
- Category
- C++
- Title
- graph using djacency matrix c++
- Category
- C++
- Title
- nan c++ example
- Category
- C++
- Title
- floor() in c++
- Category
- C++