Advertisement
Guest User

sa

a guest
Feb 23rd, 2020
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define MAX 10
  4.  
  5. int a[MAX];
  6. void lp(int,int[]);
  7. void lpsr(int,int []);
  8. void display(int []);
  9. int
  10.  
  11.  
  12. main()
  13. {
  14. int i,key,ch;
  15. for(i=0;i<MAX;i++)
  16. {
  17. a[i]='\0';
  18. }
  19. do{
  20. printf("\n\n Program or insertion/searching keys with linear probing");
  21. printf("\n1.Insert Keys");
  22. printf("\n2.Search Keys");
  23. printf("\n3.Display Keys");
  24. printf("\n4.Exit");
  25. printf("\nSelect Operation");
  26. scanf("%d",&ch);
  27. switch(ch)
  28. {
  29. case 1: do{
  30. printf("Enter key value: ");
  31. scanf("%d",&key);
  32. if(key!=-1)
  33. lp(key,a);
  34.  
  35. }
  36. while(key!=-1);
  37. display(a);
  38. break;
  39. case 2: printf("Enter search key value: ");
  40. scanf("%d",&key);
  41. lpsr(key,a);
  42. break;
  43. case 3: display(a);
  44. break;
  45. }
  46. }
  47. while(ch!=4);
  48.  
  49.  
  50.  
  51. }
  52. //insert key
  53. void lp(int key,int a[MAX])
  54. {
  55. int loc,i=1;
  56. loc=key%MAX;
  57. while(a[loc]!='\0')
  58. {
  59.  
  60. loc= (key % MAX =i*j) % MAX;
  61. i++;
  62. a[loc]=key;
  63.  
  64. }
  65.  
  66. //search
  67. void qpsr(int key,int a[MAX])
  68. {
  69. int [ioc];
  70. loc=key%MAX;
  71. while((a[loc]!=key)&&(a[loc]!='\0'))
  72. loc=++loc%MAX;
  73. if(a[loc]!='\0')
  74. printf("\n Search successful at index %d",loc);
  75. else
  76. printf("\n Search unsuccessful");
  77. }
  78.  
  79. void display(int a[MAX])
  80.  
  81. {
  82. int i;
  83. printf("\n List of keys'0' indicate that the list is empty");
  84. for (i=0;i<MAX;i++)
  85. {
  86. printf("%d",a[i]);
  87.  
  88.  
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement