#include #include #include using namespace std; class Societate{ public: string nume, adresa; int rulaj; void print(){ cout<<"Nume: "<>tmp.nume; cout<<"Adresa: "; cin>>tmp.adresa; cout<<"Rulaj: "; cin>>tmp.rulaj; v.push_back(tmp); } //sort bool sorted = false; while(!sorted){ sorted=true; for(vector::iterator it = v.begin(); it < v.end()-1; it++){ if(it->rulaj > (it+1)->rulaj){ Societate tmp = *it; *it = *(it+1); *(it+1) = tmp; sorted = false; } } } int rulaj; cout<<"Rulajul de cautat: "; cin>>rulaj; int vStart = 0; int vEnd = v.size()-1; int pos = vEnd/2; while(vStart <= vEnd && rulaj >= v[vStart].rulaj && rulaj <= v[vEnd].rulaj){ pos = vStart + (((double)(vEnd - vStart) / (v[vEnd].rulaj - v[vStart].rulaj)) * (rulaj - v[vStart].rulaj)); if(vStart == vEnd){ break; } if(v[pos].rulaj == rulaj){ break; } if(v[pos].rulaj < rulaj){ vStart = pos + 1; } else{ vEnd = pos - 1; } } cout<<"Societatea cu rulajul cel mai apropiat de "<