Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define SIZE 13
- int arr[SIZE] = {0};
- int search(int value, int type){
- int index, i = 0, count = 0;
- index = value % SIZE;
- while(arr[index] != value && count <= SIZE){
- count++;
- if(index >= SIZE) index %= SIZE;
- else{
- if(type == 1) index += (1);
- if(type == 2) index += (++i * i);
- if(type == 3) index += (7 - (index % 7));
- }
- }
- if(count > SIZE){
- printf("\nThe appropriate index is not found.");
- return -1;
- }
- return index;
- }
- void display(){
- for(int i = 0; i < SIZE; i++)
- if(arr[i] != 0) printf("arr[%d] = %d\n", i, arr[i]);
- }
- int main(){
- int choice, n, type, result;
- while(1){
- display();
- printf("\n\n1.Insert 2.Delete 3.Search 4.Exit: ");
- scanf("%d", &choice);
- switch(choice){
- case 1: printf("\nEnter a value: ");
- scanf("%d", &n);
- printf("\n1.Linear Probing 2.Quadratic Probing 3.Double Hashing: ");
- scanf("%d", &type);
- arr[search(0, type)] = n;
- break;
- case 2: printf("\nEnter a value to be deleted: ");
- scanf("%d", &n);
- arr[search(n, 1)] = 0;
- break;
- case 3: printf("\nEnter a value to be searched: ");
- scanf("%d", &n);
- printf("\n1.Linear Probing 2.Quadratic Probing 3.Double Hashing: ");
- scanf("%d", &type);
- result = search(n,type);
- if(result+1)printf("Found at %d.", result);
- break;
- case 4: return 0;
- default:printf("\nInvalid Choice.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement