LNRPROB - } printf("\tHash...

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> /* program to implement linear probing hash search */ /* 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,z; clrscr(); printf("\tHASHING USING LINEAR PROBING\n"); printf("Enter the size of the table & no of elements"); scanf("%d%d",&n,&z); printf("\tHASH table creation\n"); for(i=0;i<n;++i) hsh[i]=-1; printf("Enter the numbers : "); for(i=1;i<=z;++i) { scanf("%d",&x); index=x%n; while(hsh[index]!=-1) index=(index+1)%n; hsh[index]=x;
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(&quot;\tHash Table\n&quot;); for(i=0;i&lt;n;++i) printf(&quot;%4d &quot;,i);printf(&quot;\n&quot;); for(i=0;i&lt;n;++i) printf(&quot;%4d &quot;,hsh[i]); do { printf(&quot;\nelement to be searched (to stop enter -1) : &quot;); scanf(&quot;%d&quot;,&amp;x); if(x&gt;=0) {k=hashsearch(hsh,x,n); if(k&gt;=0) printf(&quot;%d is present at hsh[%d] &quot;,x,k); else printf(&quot;%d is NOT present&quot; ,x); } }while(x&gt;=0); getch(); } /* OUTPUT: HASHING USING LINEAR PROBING Enter the size of the table &amp; no of elements5 4 HASH table creation Enter the numbers : 23 10 15 52 Hash Table 0 1 2 3 4 10 15 52 23 -1 element to be searched (to stop enter -1) : 52 52 is present at hsh[2] element to be searched (to stop enter -1) : 14 14 is NOT present element to be searched (to stop enter -1) : -1 */...
View Full Document

Page1 / 2

LNRPROB - } printf(&amp;amp;quot;\tHash...

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