c code for quadratic probing

  • c
  • write a c code for quadratic probing

    WAP to quadratic probing or quadratic hashing

    Code

    //qudratic probing #include <stdio.h> #include <stdlib.h> #include <string.h> void printArray(int *A, int n) { for (int i = 0; i < n; i++) { printf("%d->%d \n", i, A[i]); } printf("\n"); } int hash(int key, int size) { return key % size; } int place(int H[], int key, int size) { int index = hash(key, size); int i = 0; while (H[(index + (i ^ 2))] != 0) { i++; } return (index + (i ^ 2 + i + 1)) % size; } void insert(int H[], int key, int size) { int index = hash(key, size); if (index != 0) { index = place(H, key, size); } H[index] = key; } int main() { int n = 1, e, c = 0, i; printf("enter the no of element to hash : "); scanf("%d", &i); i = i * i; int HT[i]; for (int l = 0; l < i; l++) { HT[l] = 0; } while (n != 0) { printf("enter the element to hash : "); scanf("%d", &e); insert(HT, e, i); c++; printf("want to enter more[1/0]->[yes/no] : "); scanf("%d", &n); if (c == i) { printf("cant hash exceded the limt\n"); n = 0; } } printArray(HT, i); return 0; }