Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- class Buffer {
- private:
- struct Item {
- std::string value;
- Item* prev;
- };
- Item* currentPointer;
- int counter;
- public:
- Buffer();
- ~Buffer();
- void Push(std::string X);
- std::string Pop();
- std::string Top();
- bool IsEmpty();
- void Clear();
- void HowMany();
- };
- Buffer::Buffer() {
- currentPointer = nullptr;
- counter = 0;
- };
- Buffer::~Buffer() {
- Clear();
- };
- void Buffer::Push(std::string X) {
- Item* a = new Item();
- a->value = X;
- a->prev = this->currentPointer;
- this->currentPointer = a;
- counter++;
- };
- std::string Buffer::Pop() {
- /*Item* d = this->currentPointer;*/
- std::string s = this->currentPointer->value;
- this->currentPointer = this->currentPointer->prev;
- /*delete d;*/
- counter--;
- return s;
- };
- std::string Buffer::Top(){
- return this->currentPointer->value;
- };
- bool Buffer::IsEmpty() {
- return this->currentPointer == nullptr;
- };
- void Buffer::Clear() {
- while (!IsEmpty()) {
- this->Pop();
- }
- };
- void Buffer::HowMany() {
- std::cout << "V zasobniku je " << counter << " polozek." << std::endl;
- }
- ;
- int main() {
- Buffer words;
- std::string a, b;
- a = "kunda";
- b = "kunda2";
- words.Push(a);
- words.HowMany();
- std::cout << words.Top() << std::endl;
- a = a + b;
- words.Push(a);
- std::cout << words.Top() << std::endl;
- system("pause");
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment