Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Stos
  6. {
  7. public:
  8. int *tab;
  9. int max_wierzch;
  10. int wierzcholek = -1;
  11.  
  12. int pop()
  13. {
  14. if (this->wierzcholek == -1) return 0;
  15. this->wierzcholek--;
  16. return 1;
  17. }
  18.  
  19. int push(int liczba)
  20. {
  21. if (this->wierzcholek+1>=max_wierzch) return 0;
  22. this->tab[++this->wierzcholek] = liczba;
  23. return 1;
  24. }
  25.  
  26. int top()
  27. {
  28. if (this->wierzcholek == -1) return 0;
  29. return this->tab[this->wierzcholek];
  30. }
  31.  
  32. int empty()
  33. {
  34. if (this->wierzcholek == -1) return 1;
  35. return 0;
  36. }
  37.  
  38. int full()
  39. {
  40. if (this->wierzcholek+1>=max_wierzch) return 1;
  41. return 0;
  42. }
  43.  
  44. void init(int liczba)
  45. {
  46. this->tab = new int[liczba];
  47. this->max_wierzch = liczba;
  48. }
  49.  
  50. void destroy()
  51. {
  52. delete [] this->tab;
  53. }
  54. };
  55.  
  56. int main()
  57. {
  58. Stos stos1, stos2;
  59. stos1.init(10);
  60. stos2.init(10);
  61.  
  62. int liczba;
  63. for (int i = 0; i < 10; i++)
  64. {
  65. cout << "Podaj liczbe nr " << i + 1 << ": ";
  66. cin >> liczba;
  67. stos1.push(liczba);
  68. }
  69.  
  70. cout << endl;
  71.  
  72. for (int i = 10; i > 0; i--)
  73. {
  74. stos2.push(stos1.top());
  75. cout << "Liczba nr " << i << ": " << stos1.top() << endl;
  76. stos1.pop();
  77. }
  78.  
  79. for (int i = 0; i < 10; i++)
  80. {
  81. stos1.push(stos2.top());
  82. stos2.pop();
  83. }
  84.  
  85. cout << endl;
  86. stos1.destroy();
  87. stos2.destroy();
  88. system("pause");
  89.  
  90. return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement