CodingKnight's blog

By CodingKnight, 6 years ago, In English

Hello C++ learners in Codeforces,

The following is a tutorial C++ class class tutorial_t: vector< T > that illustrates using the standard library function templates std::lower_bound and std::upper_bound.

Tutorial C++ Class

The C++ class inherits the base class vector< T > and generalizes the example given in

  1. www.cplusplus.com/reference/algorithm/lower_bound

  2. www.cplusplus.com/reference/algorithm/upper_bound

to demonstrate using both function templates for an arbitrary unsorted input array of size n, and an arbitrary value val. The item type T should be instantiated in line 5. For example, typedef double T; allows illustrating the result of searching for the lower-bound and upper-bound in a sorted array of floating-point numbers. Furthermore, standard assert( int expression ) C macro calls are used to illustrate invariant expressions that are guaranteed to be true for any test case.

UPDATE The data item typename parameter T has been removed from the class declaration so as to allow using a single member function example to illustrate both std::lower_bound and std::upper_bound functions. The corresponding function calls are passed to the example function as lambda expressions.

P.S. Downvoters are invited to share their constructive feedback fairly if they can express what they don't like about this blog, and they care to help others and have more time than the time spent to click the dislike voting button. They do not have to create other accounts in Codefores to do that.

  • Vote: I like it
  • -29
  • Vote: I do not like it