using namespace std;
int izlash(int* a, int k, int n ) {
int p=n,h=0;
while(p!=-1) {
for(int i=0; i
if(a[i]==k) {
p=i;
if(p==0) {
return h;
} else {
swap(a[i],a[i-1]);
h+=1;
}
}
}
if(h==0) p=-1;
}
return h;
}
int main() {
int i,n,k,h;
cout<<"N:"; cin>>n;
int a[n];
cout<
for(i=0; i
cin>>a[i];
}
cout<<"Izlanayotgan elementni kiriting:";
cin>>k;
h=izlash(a,k,n);
if(a[0]==k) {
cout<<"Emelent topildi, "<
} else {
cout<<"Izlanayotgan element topilmadi!";
}
}
Do'stlaringiz bilan baham: