std::lower bound
Megjelenés
Főnév
std::lower bound (tsz. std::lower bounds)
✅ std::lower_bound jelentése:
A std::lower_bound egy algoritmus a C++-ban (az <algorithm> könyvtárban), amely egy rendezett tartományban (pl. vektorban) megkeresi az első olyan pozíciót, ahol egy adott értéket be lehetne szúrni úgy, hogy a sorozat sorrendje megmaradjon.
Másképp fogalmazva:
> Az első olyan elem helyére mutat, ami nem kisebb, mint a keresett érték.
✅ Szintaxis:
auto it = std::lower_bound(begin, end, value);
begin, end: a tartomány határai (pl.ages.begin(),ages.end())value: a keresett értékit: egy iterátor, ami vagy a megtalált helyre mutat, vagy azend()-re, ha minden elem kisebb.
✅ Példa:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
vector<int> ages = {19, 21, 22, 23, 27, 30}; // Rendezett vektor!
int keresett = 22;
auto it = lower_bound(ages.begin(), ages.end(), keresett);
if (it != ages.end()) {
cout << "Az első elem, ami nem kisebb, mint " << keresett
<< " a(z) " << *it << endl;
} else {
cout << "Nincs ilyen elem." << endl;
}
}
Kimenet:
Az első elem, ami nem kisebb, mint 22 a(z) 22
✅ Tipikus használat:
- Gyors bináris keresés rendezett adatszerkezetekben.
- Megkeresni, hogy hová illesszünk be egy új elemet úgy, hogy a sorozat rendezett maradjon.
- Megszámolni, hány elem kisebb egy adott értéknél (
distance(begin, lower_bound(...))).
- std::lower bound - Szótár.net (en-hu)
- std::lower bound - Sztaki (en-hu)
- std::lower bound - Merriam–Webster
- std::lower bound - Cambridge
- std::lower bound - WordNet
- std::lower bound - Яндекс (en-ru)
- std::lower bound - Google (en-hu)
- std::lower bound - Wikidata
- std::lower bound - Wikipédia (angol)