sort function in vector c++ stl
C++
// 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;
}
Also in C++:
- Title
- ios_base::sync_with_stdio(false);cin.tie(NULL);
- Category
- C++
- Title
- new c++
- Category
- C++
- Title
- sieve of eratosthenes c++
- Category
- C++
- Title
- powers of 2 in cpp
- Category
- C++
- Title
- single line if c++
- Category
- C++
- Title
- c++ ros subscriber
- Category
- C++
- Title
- c++ multiple inheritance diamond problem
- Category
- C++
- Title
- how to initialize a vector in c++
- Category
- C++
- Title
- reverse in vector c++
- Category
- C++
- Title
- how to delete a node c++
- Category
- C++
- Title
- how to append to a vector c++
- Category
- C++
- Title
- how to concatinate two strings in c++
- Category
- C++
- Title
- how to find hcf in c++
- Category
- C++
- Title
- how to iterate through a map in c++
- Category
- C++
- Title
- change int to string cpp
- Category
- C++
- Title
- set precision in c++
- Category
- C++
- Title
- length of string c++
- Category
- C++
- Title
- maximum possible number atmost k swaps
- Category
- C++
- Title
- newline in c++
- Category
- C++
- Title
- what is meaning of 64 bit integer in c++
- Category
- C++
- Title
- dynamic 2d array c++
- Category
- C++
- Title
- error: ‘memset’ was not declared in this scope in cpp
- Category
- C++
- Title
- how to iterate over unordered_map c++
- Category
- C++
- Title
- unordered_map c++
- Category
- C++
- Title
- what is order in of preeendence in float, int, char, bool
- Category
- C++
- Title
- euler's totient function c++
- Category
- C++
- Title
- how to remove maximum number of characters in c++ cin,ignore
- Category
- C++
- Title
- declaration vs. definition cpp
- Category
- C++
- Title
- getting a random letter in c++
- Category
- C++
- Title
- basic ex of maps in c++
- Category
- C++
- Title
- Runtime Error: Runtime ErrorAbort signal from abort(3) (SIGABRT)
- Category
- C++
- Title
- how to type cast quotient of two integers to double with c++
- Category
- C++
- Title
- Qt asynchronous HTTP request
- Category
- C++
- Title
- C++ and endl
- Category
- C++
- Title
- C++ Syntax
- Category
- C++
- Title
- time function c++
- Category
- C++
- Title
- get elements of 2d array c++
- Category
- C++
- Title
- zeros of array c++
- Category
- C++
- Title
- count function c++
- Category
- C++
- Title
- Combination Sum
- Category
- C++
- Title
- C++ pointer arithmetic
- Category
- C++
- Title
- c++ code for polynomial addition
- Category
- C++
- Title
- c++ program for matrix addition
- Category
- C++
- Title
- multiset c++
- Category
- C++
- Title
- to_string c++
- Category
- C++
- Title
- how to read and write in a file c++
- Category
- C++
- Title
- what is iterator in c++?
- Category
- C++
- Title
- how to turn int into string c++
- Category
- C++
- Title
- c++ code to print hello world
- Category
- C++
- Title
- sort a pair using c++ stl
- Category
- C++
- Title
- C++ remove element from set
- Category
- C++
- Title
- c++ get length of array
- Category
- C++
- Title
- std string find character c++
- Category
- C++
- Title
- COnvert string to char * C++
- Category
- C++
- Title
- c++ pi
- Category
- C++
- Title
- initialise 2d vector in c++
- Category
- C++
- Title
- string comparison in c++
- Category
- C++
- Title
- floor() in c++
- Category
- C++
- Title
- how to convert int to string c++
- Category
- C++
- Title
- residuo en lenguaje c
- Category
- C++
- Title
- static variable in c++
- Category
- C++
- Title
- c++ class inheritance
- Category
- C++
- Title
- how to take input in C++ in coding
- Category
- C++
- Title
- minimum swaps to sort an array
- Category
- C++
- Title
- what is meaning of bus error in compattive programming
- Category
- C++
- Title
- c++ compiler for sublime text
- Category
- C++
- Title
- differentialble programming
- Category
- C++
- Title
- c++ empty stream
- Category
- C++
- Title
- C++ string format ctime
- Category
- C++
- Title
- array 2d to 1d
- Category
- C++
- Title
- c++ find prime numbers
- Category
- C++
- Title
- min coin change problem dp
- Category
- C++
- Title
- max heap c++ stl;
- Category
- C++
- Title
- self in c++
- Category
- C++
- Title
- c++ push multiple elements to vector
- Category
- C++
- Title
- Application of c++ in youtube program
- Category
- C++
- Title
- c++ how to skip the last element of vector
- Category
- C++
- Title
- deque c++
- Category
- C++
- Title
- including cpp header file in c++
- Category
- C++
- Title
- how to make movement in c++ unreal
- Category
- C++
- Title
- primeros numeros primos
- Category
- C++
- Title
- cut by delimiter c++
- Category
- C++
- Title
- c++ char to int
- Category
- C++
- Title
- quick sort predefined function in c++
- Category
- C++
- Title
- How to find the kth smallest number in cinstant space
- Category
- C++
- Title
- stl sort in c++
- Category
- C++
- Title
- find upper bound c++ vector
- Category
- C++
- Title
- check an stack is empty c++
- Category
- C++
- Title
- decimal to hex cpp
- Category
- C++
- Title
- eigenvalue of matrix c++ using Eigen
- Category
- C++
- Title
- how do for loops on c++
- Category
- C++
- Title
- nearest integer rounding in c++
- Category
- C++
- Title
- declare vectors c++
- Category
- C++
- Title
- c++ iterate over vector
- Category
- C++
- Title
- filling 2d array with 0 c++
- Category
- C++
- Title
- inheritance protected in c++
- Category
- C++
- Title
- dijkstra c++ geeksforgeeks using set
- Category
- C++
- Title
- c++ sql
- Category
- C++
- Title
- how to declare a vector in c++
- Category
- C++
- Title
- variable sized arrays hackerrank solution in c++
- Category
- C++