This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
#include <vector> | |
using namespace std; | |
int main () | |
{ | |
// lower_bound = start index of value | |
// upper_bound = ending index of value + 1; | |
int myints[] = {10, 10, 10, 20, 20, 20, 30, 30}; | |
std::vector<int> v(myints,myints+8); | |
std::sort (v.begin(), v.end()); | |
std::vector<int>::iterator low,up; | |
low = v.begin(); | |
low=std::lower_bound (v.begin(), v.end(), 10); | |
up= std::upper_bound (v.begin(), v.end(), 10); | |
std::cout << "lower_bound at position " << (low- v.begin()) << '\n'; | |
std::cout << "upper_bound at position " << (up - v.begin()) << '\n'; | |
cout << endl; | |
vector <int> vii[10]; | |
vector <int> :: iterator it; | |
// vii[0][0] = 1; | |
// vii[0][1] = 2; | |
// vii[0][2] = 3; | |
// vii[0][3] = 4; | |
vii[0].push_back(2); | |
vii[0].push_back(4); | |
vii[0].push_back(6); | |
vii[0].push_back(8); | |
it = lower_bound(vii[0].begin(), vii[0].end(), 4); | |
std::cout << "lower_bound at position " << (it - vii[0].begin()) << '\n'; | |
it = upper_bound(vii[0].begin(), vii[0].end(), 4); | |
std::cout << "upper_bound at position " << (it - vii[0].begin()) << '\n'; | |
return 0; | |
} |
Comments
Post a Comment