Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #define MAX 10
- int a[MAX];
- void qp(int ,int []);
- void qpsr(int key,int a[MAX]);
- void display(int a[MAX]);
- int main()
- {
- int i,key,ch;
- for(i=0;i<MAX;i++)
- a[i]='\0';
- do
- {
- printf("\n \n Program for intersection/searching keys with the quadratic probing");
- printf("\n \n ************************************************************\n\n");
- printf("\n 1.Insert Keys");
- printf("\n 2.Search keys");
- printf("\n 3.Display keys");
- printf("\n 4.Exit");
- printf("\nSelect the operation");
- scanf("%d",&ch);
- switch(ch)
- {
- case 1:do{
- printf("\nEnter the key value [type-1]for termination");
- scanf("%d",&key);
- if(key!=-1)
- {
- qp(key,a);
- }
- }while(key!=-1);
- display(a);
- break;
- case 2:printf("\nEnter the search key value");
- scanf("%d",&key);
- qpsr(key,a);
- break;
- case 3:display(a);
- break;
- default:printf("\nInvalid input given");
- }
- }while(ch!=4);
- }
- void qp(int key,int a[MAX])
- {
- int loc;
- int i=1;
- loc=key%MAX;
- while(a[loc]!='\0')
- {
- loc=(key %MAX+i*i)%MAX;
- i++;
- }
- a[loc]=key;
- }
- void qpsr(int key,int a[MAX])
- {
- int loc;
- loc=key% MAX;
- while((a[loc]!=key)&& (a[loc]!=-1))
- loc=++loc%MAX;
- if(a[loc]!='\0')
- printf("\nSearch successful at index %d",loc);
- else
- printf("\nSearch successful");
- }
- void display(int a[MAX])
- {
- int i;
- printf("\nList of keys('0' indicate that the location is empty):\n");
- for(i=0;i<MAX;i++)
- {
- printf("%d\t",a[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement