3- mavzu. Xesh jadval va xesh funksiyalar. Xesh funksiyalarga misol


main() { int n; coutn; struct malumot


Download 297.28 Kb.
bet10/10
Sana26.11.2021
Hajmi297.28 Kb.
#177552
1   2   3   4   5   6   7   8   9   10
Bog'liq
3-hafta. Malumotlar tuzilmasi

main()

{

int n;



cout<<"n=";cin>>n;

struct malumot

{

string FISH,tugulgan_sana, pasport;



}

shaxs[n];

for(int i=0;i

{

cout<>shaxs[i].FISH;



cout<<"Tugulgan_sana =";cin>>shaxs[i].tugulgan_sana;

cout<<"Pasport =";cin>>shaxs[i].pasport;

}
for(int i=0;i

for(int j=i+1;j

if(shaxs[i].FISH>shaxs[j].FISH)

{

malumot h=shaxs[i];



shaxs[i]=shaxs[j];

shaxs[j]=h;

}

for(int i=0;i

cout<

cout<

int low = 0,hi = n-1,search=-1,q=0;

string key; cout<<"kalit = ";

cin>>key;

while(low<=hi)

{

int mid = (low + hi) / 2;



q++;

if (key == shaxs[mid].FISH)

{

search = mid;



break;

}

if (key < shaxs[mid].tugulgan_sana)



hi = mid - 1;

else low = mid + 1;

}

if(search!=-1) cout<<"qidirilayotgan element "<

else

{

cout<

system("PAUSE");

return 0;

}
while(shaxs[search-1].FISH==key) search--;
while(shaxs[search].tugulgan_sana==key)

{

cout<

search++;

}
system("pause");


}

Natija:



Download 297.28 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   10




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