Advertisement
d1i2p3a4k5

26.Hashing(DS)

Nov 2nd, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #define hash 11
  4. void fillhash(int n,int table[][20],int count[],int a[])
  5. {
  6.     int i,j;
  7.     for(i=0;i<n;i++)
  8.     {
  9.         j = a[i]%hash;
  10.         table[j][count[j]] = a[i];
  11.         count[j]++;
  12.     }
  13. }
  14. int search(int table[hash][20],int count[],int ele)
  15. {
  16.     int hk,i;
  17.     hk = ele%hash;
  18.     for(i=0;i<count[hk];i++)
  19.     {
  20.         if(ele==table[hk][i])
  21.             return 1;
  22.     }
  23.     return 0;
  24. }
  25. void main()
  26. {
  27.     int i,j,n,ele,count[hash]={0};
  28.     int table[hash][20]={0},a[100];
  29.     printf("\nEnter size of array\n");
  30.     scanf_s("%d",&n);
  31.     for(i=0;i<n;i++)
  32.     {
  33.         printf("\nenter %d element ",(i+1));
  34.         scanf_s("%d",&a[i]);
  35.     }
  36.     printf("\n enter element to be searched");
  37.     scanf_s("%d",&ele);
  38.     fillhash(n,table,count,a);
  39.     i=search(table,count,ele);
  40.     if(i==1)
  41.         printf("\n element found");
  42.     else printf("\n elemnt not found");
  43.     _getch();
  44.    
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement