Playground
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { vector<int> v; v.push_back(3); //v={3} v.push_back(1); //v={3, 1} v.push_back(2); //v={3, 1, 2} sort(v.begin(), v.end()); //v={1, 2, 3} if (binary_search(v.begin(), v.end(), 3)) //true cout << "najdeno" << endl; //pechati 'najdeno' vector<int>::iterator it; it = lower_bound(v.begin(), v.end(), 2); cout << *it << endl; //pechati '2' it = upper_bound(v.begin(), v.end(), 2); cout << *it << endl; //pechati '3' return 0; }
Input data
Program output
no input
Execute
Language: ????????? | Memory: ???? KB | Time: ??? ms
Nothing has been executed, yet!