{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CHAINING - else{printf"hsh%d>",i ptr=hsh[i...

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> #include <stdlib.h> /* RISHI AGARWAL             HASHING:CHAINING    ROLL NO 02       SE CMPN A*/ typedef struct node { int data;   struct node *next; } NODE; int flag; 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;    for(i=0;i<10;++i) hsh[i]=NULL;    clrscr();    do{ if(x>=0) {  clrscr();  printf("           HASH TABLE \n\n");
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
 for(i=0;i<10;++i)  {printf("\n");   if(hsh[i]==NULL)printf("hsh[%d]--->NULL\n",i);
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: else {printf("hsh[%d]--->",i); ptr=hsh[i]; while(ptr!=NULL) { 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\n"); scanf("%d",&x); k=hashsearch(hsh,x,10); if(flag==1)printf("%d originally present at %u\n",x,k); else printf("%d is added into the chain at %u\n",x,k); getch(); } OUTPUT: HASH TABLE hsh[0]--->NULL hsh[1]--->NULL hsh[2]--->2-->12-->NULL hsh[3]--->NULL hsh[4]--->4-->NULL hsh[5]--->NULL hsh[6]--->6-->46-->NULL hsh[7]--->NULL hsh[8]--->8-->NULL hsh[9]--->NULL Enter a number to stop enter -1-1 Element to be searched 46 46 originally present at 2060...
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