Kommunikatsiyalarini rivojlantirish vazirligi


Download 14.43 Kb.
Sana02.12.2020
Hajmi14.43 Kb.
#157038
Bog'liq
MTvaA 3-lab


O‘ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA

KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI

MUHAMMAD AL-XORAZMIY NOMIDAGI

TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI

LABORATORIYA ISHI № 3

Guruh: 312-19-guruh

Bajardi: Ro’ziboyev Ismoil

Tekshirdi: Xojiyeva N.

Toshkent–2020

Laboratoriya ishi №3

Variant 17

Topshiriq: Boshiga qo‘yish va transpozitsiya usulidan foydalanib massiv eng kichik elementi topilsin.


1-usul: Boshiga qo’yish usuli:

#include
#include
int InSeqsearch(int realArray[], int N, int
kind[2][1000],int m,int key, int *t)
{
int i=0,
low = 0,
hi = 0;
while ((i
{
i++;
(*t)++;
}
(*t)++;
if (i==0)
low=0;
else
low=kind[1][i-1];
if (i==m)
hi=N;
else
TOSHKENT
hi=kind[1][i]-1;
for (int j=low; j<=hi; j++)
{
(*t)++;
if( key==realArray[j] )
{
return j;
} }
return -1;
}
main ()
{
int i = 0 ,
N = 0,
mas[1000] = {0},
kind[2][1000] = {0},
key = 0,
P = 0,
index = 0,
kindIndex = 0,
t = 0;
cout<
cin>>N;
cout<<"Massiv elementlarini kiriting!"<
for (i=0; i
cin>>mas[i];
cin>>key;
cout<<"Boshlangich qadamni kiriting! "<
cin>>P;
i = P-1;
while(i
{
kind[0][kindIndex] = mas[i];
kind[1][kindIndex++] = i;
i += P;
}
index = InSeqsearch(mas,N,kind,kindIndex,key, &t);
if (index == -1)
else
cout<<"Massivning eng kichik elementi "<<" "<
"<
getch();

return 0;
}

2-usul: Transpozitsiya usuli



#include
#include
int search(int a[], int N, int key, int *t)
{
int i=0;
while (i!=N)
{*t+=1;
if (a[i]==key) return i;
else i++;
}
//a[N]=key;
return -1;
}
main ()
{
int i, N, mas[1000], key, P, t=0;
cout<
cin>>N;
cout<<"Massiv elementlarini kiriting!"<
for (i=0; i
cin>>mas[i];
cin>>key;
P=search(mas,N,key,&t);
if (P==-1) cout<<"
TOSHKENT AXBOROT "<

else cout<<"Massivning eng kichik elementi : "<<" "<

"<
getch();
return 0;
}

Download 14.43 Kb.

Do'stlaringiz bilan baham:




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