Interpolation Search

Interpolation Search - low=mid+1; }...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
#include<stdio.h> #include<conio.h> /* RISHI AGARWAL             INTERPOLATION SEARCH    ROLL NO 02    SE CMPN A */ #define max 20 void display(int a[],int n) {  int i;  printf("\nLIST\n");  for(i=0;i<n;i++)  printf("%d ",a[i]); } void isort(int arr[],int n) {  int i,j,x;  for(i=1;i<=n-1;i++)  {   x=arr[i];   j=i;   {    arr[j]=arr[j-1];    j--;   }  arr[j]=x;  } } void binsrch(int a[],int key,int low,int high) {  int mid;  while(high>=low)  {   mid=low+(((high-low)*(key-a[low]))/(a[high]-a[low]));   if(a[mid]==key)   {
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
   printf("The element %d is found at position %d",a[mid],mid);    return;}   else if(a[mid]>key)   high=mid-1;   else
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: low=mid+1; } printf(&quot;Element Not Found&quot;); } void main() { int n,i,k,arr[max]; clrscr(); printf(&quot;Enter the no of data:&quot;); scanf(&quot;%d&quot;,&amp;n); printf(&quot;Enter the nos&quot;); for(i=0;i&lt;n;i++) scanf(&quot;%d&quot;,&amp;arr[i]); //Displaying List display(arr,n); //Insertion Sort isort(arr,n); //Displaying Sorted List display(arr,n); printf(&quot;\nEnter the key:&quot;); scanf(&quot;%d&quot;,&amp;k); binsrch(arr,k,0,n-1); getch(); } OUTPUT: Enter the no of data:10 Enter the nos3 15 7 18 8 10 5 16 19 23 LIST 3 15 7 18 8 10 5 16 19 23 LIST 3 5 7 8 10 15 16 18 19 23 Enter the key:16 The element 16 is found at position 6...
View Full Document

Page1 / 3

Interpolation Search - low=mid+1; }...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online