binary_search in c++ unexpected behaviour

前端 未结 4 890
暖寄归人
暖寄归人 2021-01-25 13:41

The following snippet is returning me 0. I expected it to be 1. What\'s wrong going on here?

#include 
#include 
#include 

        
4条回答
  •  长发绾君心
    2021-01-25 14:35

    binary_search says:

    Checks if the sorted range [first, last) contains an element equal to value. The first version uses operator< to compare the elements, the second version uses the given comparison function comp.

    Your list is not sorted, it contains the elements 11 and 22 prior to 10.

提交回复
热议问题