bipo143

11-02-17 data lab,

Feb 11th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.12 KB | None | 0 0
  1. void Display_Array(int b[],int k);
  2. void Edit(int b[],int pp,int vv);
  3. int Insert_LastPosition(int b[],int nn,int vv);
  4. int Insertion_specificPosition (int b[],int nn,int vv,int pp);
  5. int Deletion(int b[], int nn, int pp);
  6. int main()
  7. {
  8. int a[100],n,i,c,b=1,v,p;
  9. printf("\n Enter how many value\n");
  10. scanf("%d",&n);
  11. printf("\n Enter value\n");
  12. for(i=1;i<=n;i++)
  13. scanf("%d",&a[i]);
  14. while(b)
  15. {
  16. printf("\n-----Menu----\n");
  17. printf("\n Press 0 for Quite\n");
  18. printf("\n Press 1 for Display\n");
  19. printf("\n Press 2 for Insertion at last position\n");
  20. printf("\n Press 3 for Insertion at specific position\n");
  21. printf("\n Press 4 for Delete from specific position\n");
  22. printf("\n Press 5 for Linear search\n");
  23. printf("\n Press 6 for Bubble Sort \n");
  24. printf("\n Press 7 for Binary Search\n");
  25. printf("\n Press 8 for Edit\n");
  26. printf("\n Enter your choice\n");
  27. scanf("%d",&c);
  28. switch(c)
  29. {
  30. case 0: b=0;
  31. break;
  32. case 1: printf("\n choice Display\n");
  33. if(n!=0)
  34. Display_Array(a,n);
  35. else
  36. printf("\n No data to display\n");
  37. break;
  38. case 8: printf("\n choice=Edit\n");
  39. if(n!=0)
  40. {
  41. printf("\n Enter new value\n");
  42. scanf("%d",&v);
  43. M: printf("Enter position between %d to %d\n",1,n);
  44. scanf("%d",&p);
  45. if (p>=1 && p<=n)
  46. Edit (a,p,v);
  47.  
  48. else
  49. {
  50. printf("\n Wrong Position\n");
  51. goto M;
  52. }
  53. }
  54. else
  55. printf("No data to Edit\n");
  56. break;
  57. case 2:printf("\n Choice=Insertion at last position\n");
  58. printf("\n Enter new values\n");
  59. scanf("%d",&v);
  60. n=Insert_LastPosition(a,n,v);
  61. break;
  62.  
  63.  
  64.  
  65. case 3:printf("\n choice= Insertion at specification \n ");
  66. if (n!=0)
  67. {
  68. k:printf ("\n Enter position between %d to %d \n",1,n+1);
  69. scanf ("%d",& p);
  70. if (p>=1 && p<= n+1)
  71. {
  72. printf ("\n Enter new value \n");
  73. scanf ("%d", & v);
  74. n=Insertion_specificPosition (a,n,v,p);
  75. printf("\n\n Insreted at position %d\n",p);
  76.  
  77. }
  78. else
  79. {
  80. printf("\n wrong position");
  81. goto k;
  82. }
  83. }
  84. else
  85. printf("\n The array is ampty");
  86. break ;
  87.  
  88. case 4:printf("\n ghoice= Delete from Array\n ");
  89. if (n!=0)
  90. {
  91. z:printf("\n Enter Position betwen %d to %d",1,n);
  92. scanf("%d",&p);
  93. if (p>=1 && p<=n)
  94. {
  95. printf("\n Deleted value = %d\n",a[p]);
  96. n= Deletion (a,n,p);
  97. printf("\n Deleted successfully from position %d\n",p);
  98. }
  99. else
  100. {
  101. printf("\n wrong position");
  102. goto z;
  103. }
  104. }
  105. else
  106. printf("\n no data to delete\n");
  107. break ;
  108.  
  109.  
  110. default: printf("\n wrong choice\n");
  111. break;
  112. }
  113. }
  114. }
  115. void Display_Array(int b[],int k)
  116. {
  117.  
  118. int j;
  119. printf("\n The values are:\n");
  120. for(j=1;j<=k;j++)
  121. printf("%d\n",b[j]);
  122. }
  123. void Edit (int b[],int pp,int vv)
  124. {
  125. b[pp]=vv;
  126. printf("\n Edited Succesively\n");
  127. }
  128. int Insert_LastPosition (int b[],int nn,int vv)
  129. {
  130. b[nn+1]=vv;
  131. printf("\n Inserted successfully \n");
  132. return nn+1;
  133. }
  134. int Insertion_specificPosition (int b[],int nn,int vv,int pp)
  135. {
  136. int j ;
  137. for (j=nn; j>=pp; j--)
  138. b[j+1]=b[j];
  139. b[pp]=vv ;
  140. return nn+1;
  141. }
  142.  
  143. int Deletion(int b[], int nn, int pp)
  144. {
  145. int j ;
  146. for (j=pp; j<nn; j++)
  147. b[j]=b[j+1];
  148.  
  149. return nn-1;
  150. }
Add Comment
Please, Sign In to add comment