LINEAR PROBING - printf("%4d...

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

View Full Document Right Arrow Icon
#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)
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
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

This note was uploaded on 10/25/2010 for the course CMPN SEM4 taught by Professor Thakur during the Spring '07 term at University of Mumbai.

Page1 / 2

LINEAR PROBING - printf("%4d...

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

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