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 key,int a[MAX]);
- void display(int a[MAX]);
- void main()
- {
- int i,key,ch;
- for(i=0;i<MAX;i++)
- a[i]='\0';
- do
- {
- printf("\n\n program for insertion/searching key with linear probing");
- printf("\n");
- printf("\n1.Insert keys\n2.search key\n3.display keys\n4.exit\n select operation");
- scanf("%d",&ch);
- switch(ch)
- {
- case 1:
- do
- {
- printf("\n enter key value[type-1for termination]");
- scanf("%d",&key);
- if(key!=-1)
- lp(key,a);
- }
- while(key!=-1);
- display(a);break;
- case 2:
- printf("\n enter the searching key value");
- scanf("%d",&key);
- lpsr(key,a);
- break;
- case 3:
- display(a);
- break;
- }
- }
- while(ch!=4);
- }
- void lp(int key,int a[MAX])
- {
- int loc;
- loc=key%MAX;
- while (a[loc]!='\0')
- loc=++loc%MAX;
- a[loc]=key;
- }
- void lpsr(int key,int a[MAX])
- {
- int loc;
- 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 not successful;");
- }
- void display(int a[MAX])
- {
- int i;
- printf("\n list of keys ('0' indicate that the location is empty: \n");
- for(i=0;i<MAX;i++)
- printf("%d",a[i]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement