bipo143

data lab edit insert half full

Feb 17th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.96 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.  
  29. switch(c)
  30. {
  31.  
  32. case 0: b=0;
  33.  
  34. break;
  35.  
  36. case 1: printf("\n choice Display\n");
  37.  
  38. if(n!=0)
  39.  
  40. Display_Array(a,n);
  41. else
  42. printf("\n No data to display\n");
  43.  
  44. break;
  45.  
  46. case 8: printf("\n choice=Edit\n");
  47.  
  48. if(n!=0)
  49. {
  50. printf("\n Enter new value\n");
  51. scanf("%d",&v);
  52. M: printf("Enter position between %d to %d\n",1,n);
  53. scanf("%d",&p);
  54. if (p>=1 && p<=n)
  55.  
  56. Edit (a,p,v);
  57.  
  58. else
  59. {
  60. printf("\n Wrong Position\n");
  61. goto M;
  62. }
  63. }
  64. else
  65. printf("No data to Edit\n");
  66.  
  67. break;
  68. case 2:printf("\n Choice=Insertion at last position\n");
  69. printf("\n Enter new values\n");
  70. scanf("%d",&v);
  71. n=Insert_LastPosition(a,n,v);
  72. break;
  73.  
  74.  
  75. case 3:printf("\n Choice=Insertion at specification\n");
  76.  
  77. if(n!=0)
  78. {
  79. k:printf("\n Enter position between %d to %d\n",1,n+1);
  80. scanf("%d", &p);
  81. if(p>=1 && p<=n+1)
  82. {
  83. printf("\n Enter new value \n");
  84. scanf("%d",&v);
  85. n=Insertion_SpecificPosition(a,n,v,p);
  86. printf("\n\n Inserted at position %d\n",p);
  87. }
  88. else
  89. {
  90. printf("\n Wrong position\n");
  91. goto k;
  92. }
  93. }
  94.  
  95. else
  96. printf("\n The array is empty\n");
  97.  
  98.  
  99. case 4:printf("\n Choice=Delete from Array\n");
  100.  
  101. if(n!=0)
  102. {
  103. z:printf("\nEnter Position between %d to %d",1,n);
  104. scanf("%d",&p);
  105. if(p>=1 && p<=n)
  106. {
  107. printf("\n Deleted value= %d\n",a[p]);
  108. n=Deletion(a,n,p);
  109. printf("\n Deleted sucessfully from position %d\n",p);
  110. }
  111.  
  112. else
  113. {
  114. printf("\n Wrong position\n");
  115. goto z;
  116. }
  117. }
  118.  
  119. else
  120. {
  121.  
  122. printf("\n No data to Delete\n");
  123.  
  124. break;
  125. }
  126.  
  127. default: printf("\n wrong choice\n");
  128. break;
  129. }
  130. }
  131. }
  132.  
  133. void Display_Array(int b[],int k)
  134. {
  135.  
  136. int j;
  137. printf("\n The values are:\n");
  138. for(j=1;j<=k;j++)
  139. printf("%d\n",b[j]);
  140. }
  141. void Edit (int b[],int pp,int vv)
  142. {
  143. b[pp]=vv;
  144. printf("\n Edited Succesively\n");
  145. }
  146. int Insert_LastPosition (int b[],int nn,int vv)
  147. {
  148. b[nn+1]=vv;
  149. printf("\n Inserted successfully \n");
  150. return nn+1;
  151. }
  152.  
  153. int Insertion_SpecificPosition(int b[],int nn,int vv,int pp)
  154. {
  155. int j;
  156. for(j=nn;j>=pp;j--)
  157. b[j+1]=b[j];
  158.  
  159. b[pp]=vv;
  160.  
  161. return nn+1;
  162.  
  163. }
  164. int Deletion(int b[],int nn,int pp)
  165. {
  166. int j;
  167. for(j=pp;j<nn;j++)
  168. b[j]=b[j+1];
  169. return nn-1;
  170. }
Advertisement
Add Comment
Please, Sign In to add comment