int interpolationSearch(int arr[], int n, int x) {
int low = 0;
int high = n - 1;
while (low <= high && x >= arr[low] && x <= arr[high]) {
if (low == high) {
if (arr[low] == x)
return low;
return -1;
}
int pos = low + (((double)(high - low) /
(arr[high] - arr[low])) * (x - arr[low]));
if (arr[pos] == x)
return pos;
if (arr[pos] < x)
low = pos + 1;
else
high = pos - 1;
}
return -1;
}
int main() {
int arr[10] ;
std:: cout<<"massiv elementlarini kiriting arr= ";
for(int i=0; i<10; i++){
std::cin>>arr[i];}
int size = sizeof(arr) / sizeof(arr[0]);
// Massivni boshiga qo'yish
int temp = arr[size-1];
for (int i = size-1; i > 0; i--) {
arr[i] = arr[i-1];
}
arr[0] = temp;
// Transpozitsiya usulidan foydalanib massivni almashtirish
temp = arr[0];
arr[0] = arr[1];
arr[1] = temp;
// Eng kichik elementni topish
int smallest_element = arr[0];
std::cout << "Eng kichik element: " << smallest_element << std::endl;
int x;
std::cout << "Qidiriladigan elementni kiriting: ";
std::cin >> x;
int result = interpolationSearch(arr, size, x);
if (result == -1)
std::cout << "Element topilmadi" << std::endl;
else
std::cout << "Element indeksi: " << result << std::endl;
return 0;
}