Guest User

Untitled

a guest
Apr 26th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. class stac
  2. {
  3. public:
  4. void push(int item)
  5. {
  6. if(top>=STACK_SIZE-1)
  7. {
  8. cout<<"Full"<<endl;
  9. return;
  10. }
  11. else
  12. {
  13. if(item<min1)
  14. {
  15. min2 = min1;
  16. min1=item;
  17. }
  18. s[++top]=item;
  19. return;
  20. }
  21. }
  22.  
  23. void pop()
  24. {
  25. if(top==-1)
  26. {
  27. cout<<"Empty"<<endl;
  28. return;
  29. }
  30. else
  31. {
  32. if(s[top]==min1)
  33. {
  34. min1=min2;
  35. }
  36. top--;
  37. return;
  38. }
  39. }
  40. void mini()
  41. {
  42. if(top==-1)
  43. {
  44. cout<<"no minimum"<<endl;
  45. return;
  46. }
  47. else
  48. {
  49. cout<<min1<<endl;
  50. }
  51. }
  52.  
  53.  
  54. private:
  55. int min1 = INT_MAX;
  56. int min2;
  57. int s[STACK_SIZE];
  58. int top = -1;
  59. };
  60. int main()
  61. {
  62.  
  63. stac s1;
  64.  
  65. s1.push(5);
  66. s1.push(2);
  67. s1.push(9);
  68. s1.push(1);
  69. s1.push(24);
  70. s1.push(-1);
  71. s1.push(-87);
  72. s1.push(23);
  73. s1.mini();
  74. s1.display();
  75.  
  76. return 0;
  77. }
Add Comment
Please, Sign In to add comment