Advertisement
amrith

Untitled

Mar 10th, 2021
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. // Driver code
  4. int main()
  5. {
  6. // Input vector
  7. std::vector<int> v{ 10, 20, 30, 30, 30, 40, 50 };
  8.  
  9. // Print vector
  10. std::cout << "Vector contains :";
  11. for (unsigned int i = 0; i < v.size(); i++)
  12. std::cout << " " << v[i];
  13. std::cout << "\n";
  14.  
  15. std::vector<int>::iterator low1, low2, low3;
  16.  
  17. // std :: lower_bound
  18. low1 = std::lower_bound(v.begin(), v.end(), 30);
  19. low2 = std::lower_bound(v.begin(), v.end(), 35);
  20. low3 = std::lower_bound(v.begin(), v.end(), 55);
  21.  
  22. // Printing the lower bounds
  23. std::cout
  24. << "\nlower_bound for element 30 at position : "
  25. << (low1 - v.begin());
  26. std::cout
  27. << "\nlower_bound for element 35 at position : "
  28. << (low2 - v.begin());
  29. std::cout
  30. << "\nlower_bound for element 55 at position : "
  31. << (low3 - v.begin());
  32.  
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement