{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

LINEAR PROBING

# LINEAR PROBING - printf"M",i;printf"\n"...

This preview shows pages 1–2. Sign up to view the full content.

#include <stdio.h> #include <conio.h> /* RISHI AGARWAL         HASHING:LINEAR PROBING    ROLL NO 02       SE CMPN A*/ int hashsearch(int a[],int x,int n) {   int index,start;   index=x%n;   if(a[index]==x)return index;   else if(a[index]==-1)return -1;   else   {start=index; do   { index=(index+1)%n; if(a[index]==x)return index; else if(a[index]==-1)break;    }    while(index !=start);    return -1; } } void main() {int hsh[10],i,x,index,k,n,m;  clrscr();  printf("HASHING USING LINEAR PROBING\n\n");  printf("Enter the size of table & no of elements");  scanf("%d%d",&n,&m);   printf("      HASH table creation\n\n");  for(i=0;i<n;++i) hsh[i]=-1;  printf("Enter the numbers:");  for(i=1;i<=m;++i)  {    scanf("%d",&x);    index=x%n;    while(hsh[index]!=-1)  index=(index+1)%n;    hsh[index]=x;  }  printf("       Hash Table\n");  for(i=0;i<n;++i)

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: printf("%4d ",i);printf("\n"); for(i=0;i<n;++i) printf("%4d ",hsh[i]); do{printf("\nelement to be searched (to stop enter -1) : "); scanf("%d",&x); if(x>=0){k=hashsearch(hsh,x,n); if(k>=0) printf("%d is present at hsh[%d]",x,k); else printf("%d is NOT present" ,x); } } while(x>=0); getch(); } OUTPUT: HASHING USING LINEAR PROBING Enter the size of table & no of elements5 4 HASH table creation Enter the numbers:12 10 52 15 Hash Table 0 1 2 3 4 10 15 12 52 -1 element to be searched (to stop enter -1) : 52 52 is present at hsh[3] element to be searched (to stop enter -1) : 4 4 is NOT present element to be searched (to stop enter -1) : -1 */...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

LINEAR PROBING - printf"M",i;printf"\n"...

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

View Full Document
Ask a homework question - tutors are online