Search
 
SCRIPT & CODE EXAMPLE
 

CPP

equal_range in C++

// C++ program to demonstrate the use of std::equal_range
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    vector<int> v = { 10, 10, 30, 30, 30, 100, 10,
                      300, 300, 70, 70, 80 };
  
    // Declaring an iterator to store the
    // return value of std::equal_range
    std::pair<std::vector<int>::iterator,
              std::vector<int>::iterator> ip;
  
    // Sorting the vector v
    sort(v.begin(), v.end());
    // v becomes 10 10 10 30 30 30 70 70 80 100 300 300
  
    // Using std::equal_range and comparing the elements
    // with 30
    ip = std::equal_range(v.begin(), v.begin() + 12, 30);
  
    // Displaying the subrange bounds
    cout << "30 is present in the sorted vector from index "
         << (ip.first - v.begin()) << " till "
         << (ip.second - v.begin());
  
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: Modulo Exponentiaon,Iteratve Modulo Exponentiation 
Cpp :: stack implementation using linked list in cpp 
Cpp :: macro c++ 
Cpp :: how to open and print in a file in c++ 
Cpp :: range of long long in c++ 
Cpp :: c++ print to standard error 
Cpp :: c++ loop through array 
Cpp :: spicoli 
Cpp :: how to change string to lowercase and uperCase in c++ 
Cpp :: what is __asm in C++ 
Cpp :: c++ print number not in scientific notation 
Cpp :: bit c++ 
Cpp :: c++ product of vector 
Cpp :: qt popup window 
Cpp :: c++ declaring and initializing strings 
Cpp :: c++ loop through string 
Cpp :: how to string to integer in c++ 
Cpp :: cpp case 
Cpp :: c++ initialize array 1 to n 
Cpp :: C++ Find the sum of first n Natural Numbers 
Cpp :: c++ std::sort 
Cpp :: error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/ 
Cpp :: find max value in array c++ 
Cpp :: c++ enum 
Cpp :: docker.io : Depends: containerd (= 1.2.6-0ubuntu1~) E: Unable to correct problems, you have held broken packages 
Cpp :: int to hex arduino 
Cpp :: reading file c++ 
Cpp :: delete dynamic array c++ 
Cpp :: function c++ 
Cpp :: string to integer in c++ 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =