JoyMozumder

DS-lab1

Feb 10th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. #include<stdio.h>
  2. #define size 5
  3. int insert();
  4. int rem();
  5. int get();
  6. int find();
  7. int update();
  8. int len();
  9. int print();
  10. int item[size], length=0,current=-1;
  11.  
  12. int main()
  13. {
  14.  
  15. int i, choice;
  16.  
  17. for(;;)
  18. {
  19. printf("\n\nInsert any \n");
  20. printf("1. Insert\n");
  21. printf("2. Remove \n");
  22. printf("3. Get \n");
  23. printf("4. find\n");
  24. printf("5. Update\n");
  25. printf("6. length \n");
  26. printf("7. Print \n");
  27. printf("0. Quit \n\t");
  28.  
  29.  
  30. scanf("%d",&choice);
  31.  
  32. switch(choice)
  33. {
  34. case 1:
  35. insert();
  36. break;
  37. case 2:
  38. rem();
  39. break;
  40. case 3:
  41. get();
  42. break;
  43.  
  44. case 4:
  45. find();
  46. break;
  47. case 5:
  48. update();
  49. break;
  50. case 6:
  51. len();
  52. break;
  53. case 7:
  54. print();
  55. break;
  56. case 0:
  57. exit(0);
  58. break;
  59. default:
  60. break;
  61. }
  62. }
  63.  
  64. }
  65.  
  66.  
  67. int insert()
  68. {
  69.  
  70. if(length<size)
  71. {
  72. current++;
  73. printf("Enter the value ==>");
  74. scanf("%d",&item[current]);
  75. length=length+1;
  76. }
  77. else
  78. printf("\n\tOverflow\n");
  79.  
  80.  
  81. }
  82.  
  83. int rem()
  84. {
  85. if(length>0)
  86. {
  87. current--;
  88. length--;
  89. }
  90. else
  91. printf("\n\tUnderflow\n");
  92. }
  93.  
  94. int get()
  95. {
  96. printf("\nCurrent value:\t%d\n",item[current]);
  97. }
  98. int find()
  99. {
  100. int value,i;
  101. printf("value:");
  102. scanf("%d",&value);
  103. for(i=0;i<length;i++)
  104. {
  105. if(item[i]==value)
  106. {
  107. printf("\nIndex=%d",i);
  108. }
  109.  
  110. }
  111. }
  112.  
  113.  
  114. int update()
  115. {
  116. int index,value;
  117. printf("Index=");
  118. scanf("%d",&index);
  119. printf("\nNew Value=");
  120. scanf("%d",&value);
  121. item[index]=value;
  122. }
  123.  
  124. int len()
  125. {
  126. printf("Length=%d",length);
  127. }
  128. int print()
  129. {
  130. int i;
  131. printf("\n\nThe array is: \n");
  132. for(i=0;i<length;i++)
  133. printf("%d ",item[i]);
  134. }
Advertisement
Add Comment
Please, Sign In to add comment