CHAINING - { printf("%d-->",ptr->data);...

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 : CHAINING ROLL NO 02 SE CMPN A */ typedef struct node { int data; struct node *next; }NODE; } int flag; i NODE * hashsearch( NODE * a[],int x,int n) { NODE * ptr,*prev,*p; int index; flag=0; index=x%n; ptr=a[index];prev=NULL; while(ptr!=NULL) { if(x==ptr->data) {flag =1;return ptr;} else { prev=ptr; ptr=ptr->next; } } p=(NODE *)malloc(sizeof(NODE)); p->data=x; p->next=NULL; if(prev==NULL) a[index]=p; else prev->next=p; return p; } void main() { NODE * hsh[10],*ptr,*k; int i,x; clrscr(); for(i=0;i<10;++i) hsh[i]=NULL; do { if(x>=0) { clrscr(); printf(" HASH TABLE \n"); for(i=0;i<10;++i) { if(hsh[i]==NULL) printf("hsh[%d]--->NULL\n",i); else
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("hsh[%d]--->",i); ptr=hsh[i]; while(ptr!=NULL)
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("%d-->",ptr->data); ptr=ptr->next; } printf("NULL\n"); } } printf("Enter a number to stop enter -1\n"); scanf("%d",&x); hashsearch(hsh,x,10); } }while(x>=0); printf("Element to be searched:"); scanf("%d",&x); k=hashsearch(hsh,x,10); if(flag==1) printf("%d is present\n",x); else printf("%d is added into the chain\n",x); getch(); } /*OUTPUT: HASH TABLE hsh[0]--->NULL hsh[1]--->NULL hsh[2]--->12-->42-->NULL hsh[3]--->NULL hsh[4]--->34-->NULL hsh[5]--->65-->95-->NULL hsh[6]--->76-->NULL hsh[7]--->NULL hsh[8]--->NULL hsh[9]--->89-->NULL Enter a number to stop enter -1 -1 Element to be searched:76 76 is present */...
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

CHAINING - { printf("%d-->",ptr->data);...

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