Embercode
✕
The STLQuick quiz

Ordered lookups

6 questions. Covers Ordered sets and range lookups.

Questions 1 to 5 of 6

  1. 1. A C++ std::set named s holds {10, 20, 30}. What does s.upper_bound(20) return?
  2. 2. Why does this call fail to compile? ``cpp #include <algorithm> #include <map> int main() { std::map<int, int> m = {{10, 1}, {20, 2}, {30, 3}}; auto it = std::lower_bound(m.begin(), m.end(), 15); } ``
  3. 3. What does this program print? ``cpp #include <iostream> #include <iterator> #include <set> int main() { std::set<int> s = {10, 20, 30, 40}; auto it = s.lower_bound(25); std::cout << *it << ' ' << *std::prev(s.upper_bound(25)) << '\n'; } ``
  4. 4. What does this program print? ``cpp #include <algorithm> #include <iostream> #include <iterator> #include <vector> int main() { std::vector<int> v = {2, 4, 4, 4, 9}; auto lo = std::lower_bound(v.begin(), v.end(), 3); auto hi = std::upper_bound(v.begin(), v.end(), 9); std::cout << std::distance(lo, hi) << ' ' << (hi == v.end()) << '\n'; } ``
  5. 5. Name the member function of std::set that returns an iterator to the first element that is greater than or equal to a value. Type the name only, without parentheses.

    Type your answer.

5 question(s) left on this page.

Typed answers ignore extra spaces and, for most questions, capital letters.