Skip to content

Instantly share code, notes, and snippets.

@nak3
Created March 4, 2017 09:56
Show Gist options
  • Save nak3/c500ba29a3565c5f6f31027b0cfa240c to your computer and use it in GitHub Desktop.
Save nak3/c500ba29a3565c5f6f31027b0cfa240c to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main () {
vector<int> v{4,1,0,1,2,3,5,10,12,11};
sort(v.begin(), v.end());
cout << "i: ";
for (int i = 0; i < v.size(); i++) {
cout << i << (i!=(v.size()-1) ? " " : "\n");
}
cout << "v: ";
for (int i = 0; i < v.size(); i++) {
cout << v[i] << (i!=(v.size()-1) ? " " : "\n");
}
int low, up;
low = lower_bound(v.begin(),v.end(),3)-v.begin();
up = upper_bound(v.begin(),v.end(),3)-v.begin();
cout << "low:" << low << " up: " << up << "\n";
return 0;
}
/*
i: 0 1 2 3 4 5 6 7 8 9
v: 0 1 1 2 2 3 3 4 5 10
low:5 up: 7
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment