Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. // PO8.04.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <ctime>
  7. namespace struktury
  8. {
  9. const static int maxRozmiar = 50;
  10.  
  11. namespace tablicowe
  12. {
  13. class Stos{
  14. public:
  15. int szczyt;
  16. int tab[50];
  17. Stos()
  18. {
  19. szczyt = 0;
  20. }
  21. void push(int el)
  22. {
  23. tab[szczyt++] = el;
  24. }
  25. void pop()
  26. {
  27. szczyt--;
  28. }
  29. int top()
  30. {
  31. return tab[szczyt - 1];
  32. }
  33. bool empty()
  34. {
  35. if (szczyt == 0)
  36. return true;
  37. else
  38. return false;
  39. }
  40. bool Full()
  41. {
  42. if (szczyt == maxRozmiar)
  43. return true;
  44. else
  45. return false;
  46. }
  47. }
  48. ;
  49. }
  50. namespace listowe
  51. {
  52. class Elem {
  53. public:
  54. int l;
  55. Elem *nast;
  56. };
  57. class Stos {
  58. public:
  59. int szczyt;
  60. Elem *ostatni;
  61. Stos()
  62. {
  63. szczyt = 0;
  64. ostatni = NULL;
  65. }
  66. void pop() {
  67. Elem* tmp = ostatni;
  68. ostatni = ostatni->nast;
  69. szczyt--;
  70. delete tmp;
  71. }
  72. void push(int l) {
  73. Elem* nowy = new Elem;
  74. nowy->nast = ostatni;
  75. nowy->l = l;
  76. ostatni = nowy;
  77. szczyt++;
  78. }
  79. int top() { return ostatni->l; }
  80. bool full() {
  81. if (szczyt == maxRozmiar)
  82. return true;
  83. else
  84. return false;
  85. }
  86. bool empty() {
  87. if (szczyt == 0)
  88. return true;
  89. else
  90. return false;
  91. }
  92. ~Stos()
  93. {
  94. while (!this->empty()) {
  95. this->pop();
  96. }
  97. }
  98. };
  99. }
  100. }
  101.  
  102. int _tmain(int argc, _TCHAR* argv[])
  103. {
  104. srand(time(NULL));
  105.  
  106. using namespace struktury::listowe;
  107. {
  108. Stos s1;
  109. for (int i = 0; i < 10; i++)
  110. s1.push(rand()%100);
  111. for (int i = 0; i < 10; i++)
  112. {
  113. std::cout << s1.top() << std::endl;
  114. s1.pop();
  115. }
  116. }
  117. system("pause");
  118.  
  119. return 0;
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement