compare function in sort 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
- creare array con c++
- Category
- C++
- Title
- error: redefinition of ‘class Customer’
- Category
- C++
- Title
- new class * [] c++
- Category
- C++
- Title
- check if key exists in map c++
- Category
- C++
- Title
- *min_element in c++
- Category
- C++
- Title
- c++ ros publisher
- Category
- C++
- Title
- c++ read matttrix from text file
- Category
- C++
- Title
- remove element by index from vector c++
- Category
- C++
- Title
- kruskal's algorithm c++ hackerearth
- Category
- C++
- Title
- chess perft 5
- Category
- C++
- Title
- unordered_map c++
- Category
- C++
- Title
- lopping over an array c++
- Category
- C++
- Title
- array 2d to 1d
- Category
- C++
- Title
- c++ string contains
- Category
- C++
- Title
- list conda environments
- Category
- C++
- Title
- memcmp in cpp
- Category
- C++
- Title
- 2d vector
- Category
- C++
- Title
- convert integer to string c++
- Category
- C++
- Title
- c++ reading string
- Category
- C++
- Title
- initialize map c++
- Category
- C++
- Title
- string substr c++
- Category
- C++
- Title
- c++ map find
- Category
- C++
- Title
- std::reverse
- Category
- C++
- Title
- convert stirng to int c++
- Category
- C++
- Title
- c++ get last element in vector
- Category
- C++
- Title
- c++ dereference a pointer
- Category
- C++
- Title
- c++ how to return an empty vector
- Category
- C++
- Title
- c++ sort vector of objects by property
- Category
- C++
- Title
- c++ vector size
- Category
- C++
- Title
- converting char to int in c++
- Category
- C++
- Title
- C++ w3schools
- Category
- C++
- Title
- how to sort in descending order c++
- Category
- C++
- Title
- c++ over load oprator to print variable of clas
- Category
- C++
- Title
- nth_element c++
- Category
- C++
- Title
- range of long long in c++
- Category
- C++
- Title
- min heap declaration in c++ stl
- Category
- C++
- Title
- compare function in sort c++ stl
- Category
- C++
- Title
- trovare il valore massimo in un array c++ w3
- Category
- C++
- Title
- c++ modulo make it give only positive numbers
- Category
- C++
- Title
- string to number in c++
- Category
- C++
- Title
- count number of zeros in array in O(logN)
- Category
- C++
- Title
- kruskal c++
- Category
- C++
- Title
- initialise 2d vector in c++
- Category
- C++
- Title
- c++ class inheritance
- Category
- C++
- Title
- c++ function return array
- Category
- C++
- Title
- bfs in C++
- Category
- C++
- Title
- c++ char if
- Category
- C++
- Title
- rgb(100,100,100,0.5) validation c++
- Category
- C++
- Title
- how to make a 2d vector in c++
- Category
- C++
- Title
- count function c++
- Category
- C++
- Title
- sqrt cpp
- Category
- C++
- Title
- create a 2d array c++
- Category
- C++
- Title
- recursion in cpp with reference
- Category
- C++
- Title
- c++ program for addition of two numbers using functions
- Category
- C++
- Title
- c++ remove item from list
- Category
- C++
- Title
- check for bst
- Category
- C++
- Title
- visual studio 2019 c++ tutorial project
- Category
- C++
- Title
- passing a vector to a function c++
- Category
- C++
- Title
- std string find character c++
- Category
- C++
- Title
- c++ vector iterator
- Category
- C++
- Title
- widechartomultibyte
- Category
- C++
- Title
- is not a nonstatic data member or base class of class
- Category
- C++
- Title
- how to turn int into string c++
- Category
- C++
- Title
- level order traversal
- Category
- C++
- Title
- Merge k sorted linked lists and return it as one sorted list.
- Category
- C++
- Title
- free or delete in c++
- Category
- C++
- Title
- friend function in c++
- Category
- C++
- Title
- multiset c++
- Category
- C++
- Title
- c++ assert
- Category
- C++
- Title
- linkedlist implementation in c++
- Category
- C++
- Title
- do while loop c++
- Category
- C++
- Title
- container class in c++
- Category
- C++
- Title
- queue c++
- Category
- C++
- Title
- correct sequence of compilation process in c++
- Category
- C++
- Title
- how can make string value in cpp
- Category
- C++
- Title
- Find a element in a map C++
- Category
- C++
- Title
- C++ while
- Category
- C++
- Title
- for loop in c++ hackerrank solution
- Category
- C++
- Title
- & in xml
- Category
- C++
- Title
- how to print for limited decimal values in c++
- Category
- C++
- Title
- c++ return multiple values
- Category
- C++
- Title
- run program until ctrl-d c++
- Category
- C++
- Title
- how to convert number to string
- Category
- C++
- Title
- c++ looping through a vector
- Category
- C++
- Title
- sort function in c++
- Category
- C++
- Title
- array syntax in c++
- Category
- C++
- Title
- set in c++
- Category
- C++
- Title
- convert decimal to binary in c++
- Category
- C++
- Title
- flushing output in c++
- Category
- C++
- Title
- c++ class template
- Category
- C++
- Title
- c++ create array
- Category
- C++
- Title
- passing array to function c++ pointer
- Category
- C++
- Title
- lisy stl C++
- Category
- C++
- Title
- monotonic deque
- Category
- C++
- Title
- index string c++
- Category
- C++
- Title
- ue4 c++ array
- Category
- C++
- Title
- subtracting two large numbers
- Category
- C++
- Title
- pionter in c++
- Category
- C++
- Title
- factorial in c++
- Category
- C++
- Title
- c++ typeid get type name
- Category
- C++