Binary Search functions in C++ stl (binary search, lower bound and upper bound)


Download 14.38 Kb.
Sana06.06.2020
Hajmi14.38 Kb.
#115406
Bog'liq
59(1-darajali)

Binary Search functions in C++ STL (binary_search, lower_bound and upper_bound)


binary_search(start_ptr, end_ptr, num) : Agar element kontenerda bo’lsa rost aks holda yolg’on qiymat qaytaradi

#include 

using namespace std;

  

int main()



{

    // initializing vector of integers

    vector arr = {10, 15, 20, 25, 30, 35};

      


    // using binary_search to check if 15 exists

    if (binary_search(arr.begin(), arr.end(), 15))

       cout << "15 vectorda mavjud";

    else 

       cout << "15 mavjud emas ";

       


    cout << endl;

      


    // using binary_search to check if 23 exists

    if (binary_search(arr.begin(), arr.end(), 23))

         cout << "23 vectorda mavjud";

    else 

         cout << "23 mavjud emas";

       


    cout << endl;    

}


15 vectorda mavjud

23 mavjud emas
Download 14.38 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling