I have a set and I want to find the largest number, not more than x in it. (something like lower_bound (x)), how should I do this? Are there any predefined functions?
set<int> myset; myset.insert(blahblahblah); int y; //I want y to be greatest number in myset not greater than x
You can use upper_boundthe following way: upper_bound(x)--. The upper bound gives you the first element to exceed x, so the element you are looking for is the one that was before. You need a special case if upper_boundreturns begin().
upper_bound
upper_bound(x)--
x
begin()
In addition to lower_bound, there is also upper_bound C ++ Link
, . begin(), , , .
Source: https://habr.com/ru/post/1770274/More articles:How does Facebook grab article text when pasting an url? - ajaxHow to determine when the input is alphabetic? - pythonActive Directory Web Services (ADWS) SDK - soapDataGridView: how to enable multiple row selection but disable multiple cell selection? - c #MVVM-PRISM, how to display multiple instances of a view in a region / ItemsControl - dependency-injectionPython Cycling binary file - remove from start add to end - pythonHash table. Name history. Why not a HashTable? - javaSetLayeredWindowAttributes does not work on Windows 7 - c ++Delphi: dynamically create a TClientSocket - delphiИспользование XDebug с терминала (доступ только для SSH) - debuggingAll Articles