fojtasd

Untitled

Apr 8th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. class Buffer {
  5. private:
  6.     struct Item {
  7.         std::string value;
  8.         Item* prev;
  9.     };
  10.     Item* currentPointer;
  11.     int counter;
  12.  
  13. public:
  14.     Buffer();
  15.     ~Buffer();
  16.     void Push(std::string X);
  17.     std::string Pop();
  18.     std::string Top();
  19.     bool IsEmpty();
  20.     void Clear();
  21.     void HowMany();
  22.  
  23. };
  24.  
  25. Buffer::Buffer() {
  26.     currentPointer = nullptr;
  27.     counter = 0;
  28. };
  29.  
  30. Buffer::~Buffer() {
  31.     Clear();
  32. };
  33.  
  34. void Buffer::Push(std::string X) {
  35.    
  36.     Item* a = new Item();
  37.     a->value = X;
  38.     a->prev = this->currentPointer;
  39.     this->currentPointer = a;
  40.     counter++;
  41. };
  42.  
  43. std::string Buffer::Pop() {
  44.     /*Item* d = this->currentPointer;*/
  45.     std::string s = this->currentPointer->value;
  46.     this->currentPointer = this->currentPointer->prev;
  47.     /*delete d;*/
  48.     counter--;
  49.     return s;
  50. };
  51.  
  52. std::string Buffer::Top(){
  53.     return this->currentPointer->value;
  54. };
  55.  
  56. bool Buffer::IsEmpty() {
  57.     return this->currentPointer == nullptr;
  58. };
  59.  
  60. void Buffer::Clear() {
  61.     while (!IsEmpty()) {
  62.         this->Pop();
  63.     }
  64.  
  65. };
  66.  
  67. void Buffer::HowMany() {
  68.     std::cout << "V zasobniku je " << counter << " polozek." << std::endl;
  69. }
  70. ;
  71. int main() {
  72.     Buffer words;
  73.     std::string a, b;
  74.     a = "kunda";
  75.     b = "kunda2";
  76.  
  77.     words.Push(a);
  78.     words.HowMany();
  79.     std::cout << words.Top() << std::endl;
  80.     a = a + b;
  81.     words.Push(a);
  82.     std::cout << words.Top() << std::endl;
  83.  
  84.    
  85.  
  86.     system("pause");
  87.     return 1;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment