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 lp(int,int[]);
- void lpsr(int,int []);
- void display(int []);
- int
- main()
- {
- int i,key,ch;
- for(i=0;i<MAX;i++)
- {
- a[i]='\0';
- }
- do{
- printf("\n\n Program or insertion/searching keys with linear probing");
- printf("\n1.Insert Keys");
- printf("\n2.Search Keys");
- printf("\n3.Display Keys");
- printf("\n4.Exit");
- printf("\nSelect Operation");
- scanf("%d",&ch);
- switch(ch)
- {
- case 1: do{
- printf("Enter key value: ");
- scanf("%d",&key);
- if(key!=-1)
- lp(key,a);
- }
- while(key!=-1);
- display(a);
- break;
- case 2: printf("Enter search key value: ");
- scanf("%d",&key);
- lpsr(key,a);
- break;
- case 3: display(a);
- break;
- }
- }
- while(ch!=4);
- }
- //insert key
- void lp(int key,int a[MAX])
- {
- int loc,i=1;
- loc=key%MAX;
- while(a[loc]!='\0')
- {
- loc= (key % MAX =i*j) % MAX;
- i++;
- a[loc]=key;
- }
- //search
- void qpsr(int key,int a[MAX])
- {
- int [ioc];
- loc=key%MAX;
- while((a[loc]!=key)&&(a[loc]!='\0'))
- loc=++loc%MAX;
- if(a[loc]!='\0')
- printf("\n Search successful at index %d",loc);
- else
- printf("\n Search unsuccessful");
- }
- void display(int a[MAX])
- {
- int i;
- printf("\n List of keys'0' indicate that the list is empty");
- for (i=0;i<MAX;i++)
- {
- printf("%d",a[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement