for(int i=0;i
cout<
cout<
int low = 0,hi = n-1,search=-1,q=0;
string key="TTJ";
while(low<=hi){
int mid = (low + hi) / 2;
q++;
if (key == talaba[mid].adres){
search = mid;
break;
}
if (key < talaba[mid].adres)
hi = mid - 1;
else low = mid + 1;
}
if(search!=-1) cout<<"qidirilayotgan el "<turibdi va "<
else {cout<
system("PAUSE");
return EXIT_SUCCESS;
}
while(talaba[search-1].adres==key) search--;
while(talaba[search].adres==key) {
cout<
"<
search++;
}
system("pause");
}
Dastur natijasi:
n=5
1-talabaning fio=fam1
adres=Toshkent
2-talabaning fio=fam2
adres=TTJ
3-talabaning fio=fam3
adres=ijarada
4-talabaning fio=fam4
adres=uchastkada
5-talabaning fio=fam5
adres=TTJ
fam2 TTJ
fam5 TTJ
fam1 Toshkent
fam3 ijarada
fam4 uchastkada
qidirilayotgan el 1-orinda turubdi va 2 ta solishtirishda topildi
fam2 TTJ
fam5 TTJ
Nazorat savollari
1. Qanday qidiruv algoritmlarini bilasiz?
2. Qidiruv jarayonining tezligi nimalarga bog’liq?
3. Statik tuzilmadan birorta elementni izlashning qanday usullari mavjud?
4. Ro’yhat tuzilmasidan elementlarni izlab topish tezligini oshirish uchun
qanday algoritmlar mavjud?
5. Binar qidiruvni ro’yhat tuzilmasiga qo’llab bo’ladimi? Sababini asoslang.
Dostları ilə paylaş: