{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Indexed Sequential Search - clrscr printf"Enter the no...

Info icon This 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     INDEXED SEQUENTIAL 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;   while((arr[j-1]>x)&&(j>0))   {    arr[j]=arr[j-1];    j--;   }  arr[j]=x;  } } void idxseqsrch(int a[],int key,int k[][2],int j) {  int i,start,end;  for(i=0;i<j&&k[i][0]<key;i++);  if(i!=0)  start=k[i-1][1];  else  start=k[i][1];
Image of page 1

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

View Full Document Right Arrow Icon
 end=k[i][1];  for(i=start;i<end&&a[i]<key;i++);  if(a[i]==key)  printf("The element %d is found at position %d",a[i],i);  else  printf("Element Not Found"); } void main() {  int n,i,j,k,key[10][2],arr[max];
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: clrscr(); printf("Enter the no of data:"); scanf("%d",&n); printf("Enter the nos"); for(i=0;i<n;i++) scanf("%d",&arr[i]); //Displaying List display(arr,n); //Insertion Sort isort(arr,n); //Displaying Sorted List display(arr,n); for(i=0,j=0;i<n;i+=3,j++) { key[j][0]=arr[i]; key[j][1]=i; } if(i-3<n-1) { key[j][0]=arr[n-1]; key[j][1]=n-1; j++; } printf("\nEnter the key:"); scanf("%d",&k); idxseqsrch(arr,k,key,j); getch(); } /* OUTPUT: Enter the no of data:6 Enter the nos9 3 8 2 6 4 LIST 9 3 8 2 6 4 LIST 2 3 4 6 8 9 Enter the key:2 The element 2 is found at position 0 */...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern