Advertisement
Guest User

StosikSierpien

a guest
Jul 25th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct stos
  6. {
  7. public:
  8. const int rozmiar;
  9. int *dane;
  10. int wskStos;
  11. stos(int _rozmiar):rozmiar(_rozmiar)
  12. {
  13. wskStos=-1;
  14. dane=new int[rozmiar];
  15. }
  16. void wyswietl()
  17. {
  18. cout << "Stos: " << endl;
  19. for(int i=wskStos; i>=0; i--)
  20. {
  21. cout << dane[i] <<endl;
  22. }
  23. if(wskStos==0)
  24. {
  25. cout << "Stos jest pusty" << endl;
  26. }
  27. }
  28. int top()
  29. {
  30. return dane[wskStos];
  31. }
  32.  
  33. void empty()
  34. {
  35.  
  36. if (wskStos<0)
  37. cout << "stos pusty" <<endl;
  38. else
  39. cout << "stos nie jest pusty" <<endl;
  40. }
  41. int push(int liczba)
  42. {
  43. if(wskStos>=rozmiar)
  44. {
  45. cout << "Stos pelny!" << endl;
  46. }
  47. else
  48. {
  49. wskStos=wskStos+1;
  50. dane[wskStos]=liczba;
  51.  
  52. }
  53. }
  54. void pop()
  55. {
  56. if (wskStos>0)
  57. {
  58. cout<<"Zostanie usunieta liczba: "<<dane[wskStos]<<endl;
  59. wskStos=wskStos-1;
  60. }
  61. else
  62. {
  63. cout << "Stos pusty!" << endl;
  64. }
  65. }
  66. };
  67.  
  68. int main()
  69. {
  70. stos s1(5);
  71. s1.empty();
  72. s1.push(4);
  73. s1.push(3);
  74. s1.push(7);
  75. s1.push(1);
  76. cout << s1.top() << endl;
  77. s1.pop();
  78. cout << s1.top() << endl;
  79. s1.empty();
  80.  
  81. return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement