From 86b067a6063eb0d760530e383fdb4c11b9fc3fed Mon Sep 17 00:00:00 2001 From: Nikiroy78 <35032449+Nikiroy78@users.noreply.github.com> Date: Fri, 23 Jun 2023 17:03:50 +0300 Subject: [PATCH] Add stack linker --- .../Testing/Temporary/LastTest.log | 4 +-- source/CMakeLists.txt.user | 19 +------------ source/stack.cpp | 28 ++++++++++++++++++- source/stack.h | 4 +++ 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/build-source-Desktop_Qt_6_4_1_MinGW_64_bit-Debug/Testing/Temporary/LastTest.log b/build-source-Desktop_Qt_6_4_1_MinGW_64_bit-Debug/Testing/Temporary/LastTest.log index fe3c4b9..420d682 100644 --- a/build-source-Desktop_Qt_6_4_1_MinGW_64_bit-Debug/Testing/Temporary/LastTest.log +++ b/build-source-Desktop_Qt_6_4_1_MinGW_64_bit-Debug/Testing/Temporary/LastTest.log @@ -1,3 +1,3 @@ -Start testing: May 09 20:48 RTZ 2 () +Start testing: Jun 23 16:16 RTZ 2 () ---------------------------------------------------------- -End testing: May 09 20:48 RTZ 2 () +End testing: Jun 23 16:16 RTZ 2 () diff --git a/source/CMakeLists.txt.user b/source/CMakeLists.txt.user index 9b38c36..c841450 100644 --- a/source/CMakeLists.txt.user +++ b/source/CMakeLists.txt.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -375,23 +375,6 @@ true true true - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - 2 diff --git a/source/stack.cpp b/source/stack.cpp index da6f9cc..bb840e4 100644 --- a/source/stack.cpp +++ b/source/stack.cpp @@ -1,6 +1,11 @@ #include "stack.h" #include +int bytesToInt (vector> bytes) { + // (!) Сделать потом + return 0; +} + Stack::Stack() { this->stackStorage.clear(); this->stackPointer = -1; @@ -11,11 +16,31 @@ Stack::~Stack () { vector Stack::get () { if (this->stackStorage.size() == 0) return {}; - else return this->stackStorage[this->stackPointer]; + vector result = this->stackStorage[this->stackPointer]; + if (this->stackLinker[this->stackPointer] != -1) { + if ( + this->stackLinker.size() < bytesToInt(this->stackStorage[this->stackPointer]) + ) { + // (!) Выдать ошибку: такого элемента не существует + } + else if ( + bytesToInt(this->stackStorage[this->stackPointer]) == this->stackPointer + ) { + // (!) Выдать ошибку: ссылочный элемент не может ссылаться на самого себя + } + else { + this->stackPointer = bytesToInt(this->stackStorage[this->stackPointer]); + return this->get(); + } + } + else { + return result; + } } void Stack::push (vector data) { this->stackStorage.push_back(data); + this->stackLinker.push_back(-1); this->stackPointer = this->stackStorage.size() - 1; /*if (this->readMode) { // (!) Выдать ошибку: стек открыт только для чтения @@ -35,6 +60,7 @@ void Stack::rm (byte removeMode) { else { // (!) Вот тут очистить по индексу this->stackStorage.pop_back(); + this->stackLinker.pop_back(); if (this->stackStorage.size() <= this->stackPointer) { this->stackPointer--; } diff --git a/source/stack.h b/source/stack.h index 227b25f..e431aed 100644 --- a/source/stack.h +++ b/source/stack.h @@ -5,6 +5,8 @@ using std::byte; using std::vector; +int bytesToInt (vector> bytes); + class Stack { public: Stack(); @@ -20,6 +22,8 @@ private: int stackPointer = -1; int stackSize = 0; vector> stackStorage = {}; + // Link: -1 - Not Link; 0 - Link to stack; 1 - Link to heap + vector stackLinker = {}; }; #endif // STACK_H