From 93ae4a0661ea63463ef3b265ac882c13e6a16f8d Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 11 Sep 2024 11:18:33 +0300 Subject: [PATCH 01/73] Create Lab1CPP --- Lab1CPP | 1 + 1 file changed, 1 insertion(+) create mode 100644 Lab1CPP diff --git a/Lab1CPP b/Lab1CPP new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/Lab1CPP @@ -0,0 +1 @@ + From f54d5e7bea62b7666b76639582086caae13380fa Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 11 Sep 2024 11:20:06 +0300 Subject: [PATCH 02/73] Update CMakeLists.txt --- CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b40c0dd11c..daa103b658 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,9 +10,9 @@ else() add_compile_options(-Wall -Wextra -Wpedantic -Wno-gnu-empty-struct -Wno-unused-parameter) endif() -add_subdirectory(LibraryC) +#add_subdirectory(LibraryC) add_subdirectory(LibraryCPP) -add_subdirectory(LibraryCPPClass) -add_subdirectory(LibraryCPPTemplate) +#add_subdirectory(LibraryCPPClass) +#add_subdirectory(LibraryCPPTemplate) -add_subdirectory(Lab1C) +add_subdirectory(Lab1CPP) From bbced65f7aa7be4ada97236c7bf18579b9016ca1 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 11 Sep 2024 11:23:55 +0300 Subject: [PATCH 03/73] Delete Lab1CPP --- Lab1CPP | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Lab1CPP diff --git a/Lab1CPP b/Lab1CPP deleted file mode 100644 index 8b13789179..0000000000 --- a/Lab1CPP +++ /dev/null @@ -1 +0,0 @@ - From 10d045892fdfa5d880784fb9c0c34de9cb94d527 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 11 Sep 2024 11:24:31 +0300 Subject: [PATCH 04/73] Create 1 --- Lab1CPP/1 | 1 + 1 file changed, 1 insertion(+) create mode 100644 Lab1CPP/1 diff --git a/Lab1CPP/1 b/Lab1CPP/1 new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/Lab1CPP/1 @@ -0,0 +1 @@ + From e08eb2bf436217bd9cb7c147dbb41f257ed3dd96 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 11 Sep 2024 11:24:47 +0300 Subject: [PATCH 05/73] Delete Lab1CPP/1 --- Lab1CPP/1 | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Lab1CPP/1 diff --git a/Lab1CPP/1 b/Lab1CPP/1 deleted file mode 100644 index 8b13789179..0000000000 --- a/Lab1CPP/1 +++ /dev/null @@ -1 +0,0 @@ - From be9b3b3defa94810de2ed110a6c1c515056cd8d5 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 11 Sep 2024 11:25:38 +0300 Subject: [PATCH 06/73] Create CMakeList.txt --- Lab1CPP/CMakeList.txt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Lab1CPP/CMakeList.txt diff --git a/Lab1CPP/CMakeList.txt b/Lab1CPP/CMakeList.txt new file mode 100644 index 0000000000..174fd1d25d --- /dev/null +++ b/Lab1CPP/CMakeList.txt @@ -0,0 +1,5 @@ +add_executable(Lab1CPP lab1.cpp) +target_include_directories(Lab1CPP PUBLIC ../LibraryCPP) +target_link_libraries(Lab1CPP LibraryCPP) + +add_test(NAME TestLab1C COMMAND Lab1CPP ${CMAKE_CURRENT_SOURCE_DIR}/input.txt) From 4ca63f42c5d8433a725ba6bfa14df93e73994a6b Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 11 Sep 2024 11:26:07 +0300 Subject: [PATCH 07/73] Create input.txt --- Lab1CPP/input.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Lab1CPP/input.txt diff --git a/Lab1CPP/input.txt b/Lab1CPP/input.txt new file mode 100644 index 0000000000..de057f57a7 --- /dev/null +++ b/Lab1CPP/input.txt @@ -0,0 +1,4 @@ +5 +10 +20 +40 From 17b6188ade535de752f3660d6db5ffac9cbd0161 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 11 Sep 2024 11:26:58 +0300 Subject: [PATCH 08/73] Add files via upload --- Lab1CPP/lab1.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Lab1CPP/lab1.cpp diff --git a/Lab1CPP/lab1.cpp b/Lab1CPP/lab1.cpp new file mode 100644 index 0000000000..8040453060 --- /dev/null +++ b/Lab1CPP/lab1.cpp @@ -0,0 +1,57 @@ +#include +#include +#include +#include "array.h" + +Data task_1(Array* array, size_t size) +{ + Data result = 0; + + array = create_random_array(size); + + for (int i = 1; i < array_size(array); i += 2) + { + if (array_get(array, i) > 0) + { + result += array_get(array, i); + } + } + return result; +} + +void task_2(Array* array, size_t size, Data a, Data b) +{ + array = create_random_array(size); + + for (int i = 0; i < array_size(array); i++) + { + if (array_get(array, i) >= a && array_get(array, i) <= b) + { + array_erase(array, i); + i--; + } + } +} + +int main() +{ + Array* arr = nullptr; + size_t size; + std::ifstream in("input.txt"); + if (in.is_open()) + { + in >> size; + task_1(arr, size); + array_delete(arr); + + Data a, b; + in >> size; + in >> a; + in >> b; + task_2(arr, size, a, b); + array_delete(arr); + } + in.close(); + + return 0; +} \ No newline at end of file From ee95690eb27636822e27a8480624f32e0228e73f Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 11 Sep 2024 11:27:42 +0300 Subject: [PATCH 09/73] Update CMakeLists.txt --- LibraryCPP/Tests/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/LibraryCPP/Tests/CMakeLists.txt b/LibraryCPP/Tests/CMakeLists.txt index c903f9d7f3..98d8c01fd6 100644 --- a/LibraryCPP/Tests/CMakeLists.txt +++ b/LibraryCPP/Tests/CMakeLists.txt @@ -1,7 +1,7 @@ -# add_executable(TestArrayCPP array.cpp) -# target_include_directories(TestArrayCPP PUBLIC ..) -# target_link_libraries(TestArrayCPP LibraryCPP) -# add_test(TestArrayCPP TestArrayCPP) +add_executable(TestArrayCPP array.cpp) +target_include_directories(TestArrayCPP PUBLIC ..) +target_link_libraries(TestArrayCPP LibraryCPP) +add_test(TestArrayCPP TestArrayCPP) # add_executable(TestListCPP list.cpp) # target_include_directories(TestListCPP PUBLIC ..) From 0f95d0ad3d9510ad751212cf23ab4c897f1ec6ab Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 11 Sep 2024 11:28:34 +0300 Subject: [PATCH 10/73] Update array.cpp --- LibraryCPP/array.cpp | 84 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 75 insertions(+), 9 deletions(-) diff --git a/LibraryCPP/array.cpp b/LibraryCPP/array.cpp index c773e5f167..c304419c32 100644 --- a/LibraryCPP/array.cpp +++ b/LibraryCPP/array.cpp @@ -1,34 +1,100 @@ #include "array.h" +#include "time.h" + +typedef int Data; +typedef unsigned int size_t; struct Array { + Data* array; + size_t size; }; // create array -Array *array_create(size_t size) +Array* array_create(size_t size) { - return new Array; + if (size != 0) + { + Array* array = new Array; + array->size = size; + array->array = new Data[size]; + return array; + } + else + return nullptr; } // delete array, free memory -void array_delete(Array *arr) +void array_delete(Array* arr) { - delete arr; + if (arr != nullptr) + { + if (arr->array != nullptr) + { + delete[] arr->array; + delete arr; + } + } } // returns specified array element -Data array_get(const Array *arr, size_t index) +Data array_get(const Array* arr, size_t index) { - return (Data)0; + if (index < arr->size) + return arr->array[index]; + else + return 0; } // sets the specified array element to the value -void array_set(Array *arr, size_t index, Data value) +void array_set(Array* arr, size_t index, Data value) { + if (index < arr->size) + { + arr->array[index] = value; + } } // returns array size -size_t array_size(const Array *arr) +size_t array_size(const Array* arr) { - return 0; + if (arr != nullptr) + { + if (arr->array != nullptr) + return arr->size; + } + return 0; +} + +void array_erase(Array* arr, size_t index) +{ + if (index >= 0 && index < arr->size) + { + if (index == arr->size - 1) + { + arr->array[index] = 0; + } + else + { + for (int i = index; i < array_size(arr) - 1; i++) + { + arr->array[i] = arr->array[i + 1]; + } + arr->array[arr->size - 1] = 0; + } + } +} + +Array* create_random_array(Data size) +{ + srand(time(NULL)); + + Array* arr = array_create(size); + + for (int i = 0; i < size; i++) + { + Data value = rand() % (3 - 3 + 1) + 3; + array_set(arr, i, value); + } + return arr; } From 06d4f596a15886ccd00c44bcfd415e56c2feccc9 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 11 Sep 2024 11:29:09 +0300 Subject: [PATCH 11/73] Update array.h --- LibraryCPP/array.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/LibraryCPP/array.h b/LibraryCPP/array.h index b541ebe8b4..a8d133eac4 100644 --- a/LibraryCPP/array.h +++ b/LibraryCPP/array.h @@ -1,7 +1,9 @@ #ifndef ARRAY_H #define ARRAY_H +#include #include +#include // Non-resizeable array // Stores integer values inside @@ -24,4 +26,8 @@ void array_set(Array *arr, size_t index, Data value); // returns array size size_t array_size(const Array *arr); +Array* create_random_array(Data size); + +void array_erase(Array* arr, size_t index); + #endif From 78f811300e496bb748ea84d0be46041cea6b038a Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 11 Sep 2024 11:29:43 +0300 Subject: [PATCH 12/73] =?UTF-8?q?Create=20=D0=9C=D0=B8=D1=85=D0=B0=D0=B9?= =?UTF-8?q?=D0=BB=D0=BE=D0=B2=20=D0=A0=D0=BE=D0=BC=D0=B0=D0=BD=203091?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...20\276\320\262 \320\240\320\276\320\274\320\260\320\275 3091" | 1 + 1 file changed, 1 insertion(+) create mode 100644 "\320\234\320\270\321\205\320\260\320\271\320\273\320\276\320\262 \320\240\320\276\320\274\320\260\320\275 3091" diff --git "a/\320\234\320\270\321\205\320\260\320\271\320\273\320\276\320\262 \320\240\320\276\320\274\320\260\320\275 3091" "b/\320\234\320\270\321\205\320\260\320\271\320\273\320\276\320\262 \320\240\320\276\320\274\320\260\320\275 3091" new file mode 100644 index 0000000000..42089a4ec4 --- /dev/null +++ "b/\320\234\320\270\321\205\320\260\320\271\320\273\320\276\320\262 \320\240\320\276\320\274\320\260\320\275 3091" @@ -0,0 +1 @@ +Михайлов Роман 3091 From 52501111e63701e4bc327ffb80fe6a8f55dd87dd Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 11 Sep 2024 11:47:06 +0300 Subject: [PATCH 13/73] Update CMakeList.txt --- Lab1CPP/CMakeList.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lab1CPP/CMakeList.txt b/Lab1CPP/CMakeList.txt index 174fd1d25d..8ff312b8be 100644 --- a/Lab1CPP/CMakeList.txt +++ b/Lab1CPP/CMakeList.txt @@ -2,4 +2,4 @@ add_executable(Lab1CPP lab1.cpp) target_include_directories(Lab1CPP PUBLIC ../LibraryCPP) target_link_libraries(Lab1CPP LibraryCPP) -add_test(NAME TestLab1C COMMAND Lab1CPP ${CMAKE_CURRENT_SOURCE_DIR}/input.txt) +add_test(NAME TestLab1CPP COMMAND Lab1CPP ${CMAKE_CURRENT_SOURCE_DIR}/input.txt) From a25e4700fc85ae15ccfe0c7cd50f2172dc750670 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 11 Sep 2024 11:48:12 +0300 Subject: [PATCH 14/73] Update CMakeList.txt --- Lab1CPP/CMakeList.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lab1CPP/CMakeList.txt b/Lab1CPP/CMakeList.txt index 8ff312b8be..f5ff0cad70 100644 --- a/Lab1CPP/CMakeList.txt +++ b/Lab1CPP/CMakeList.txt @@ -2,4 +2,4 @@ add_executable(Lab1CPP lab1.cpp) target_include_directories(Lab1CPP PUBLIC ../LibraryCPP) target_link_libraries(Lab1CPP LibraryCPP) -add_test(NAME TestLab1CPP COMMAND Lab1CPP ${CMAKE_CURRENT_SOURCE_DIR}/input.txt) +#add_test(NAME TestLab1CPP COMMAND Lab1CPP ${CMAKE_CURRENT_SOURCE_DIR}/input.txt) From 496f8ce9059839b2d81832eded34cbdc0da053d6 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 11 Sep 2024 12:04:08 +0300 Subject: [PATCH 15/73] Rename CMakeList.txt to CMakeLists.txt --- Lab1CPP/{CMakeList.txt => CMakeLists.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Lab1CPP/{CMakeList.txt => CMakeLists.txt} (100%) diff --git a/Lab1CPP/CMakeList.txt b/Lab1CPP/CMakeLists.txt similarity index 100% rename from Lab1CPP/CMakeList.txt rename to Lab1CPP/CMakeLists.txt From 0283fa56c4fca66cbfa022cd9e8b8ec52d2ad300 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 11 Sep 2024 12:08:14 +0300 Subject: [PATCH 16/73] Update CMakeLists.txt --- Lab1CPP/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lab1CPP/CMakeLists.txt b/Lab1CPP/CMakeLists.txt index f5ff0cad70..8ff312b8be 100644 --- a/Lab1CPP/CMakeLists.txt +++ b/Lab1CPP/CMakeLists.txt @@ -2,4 +2,4 @@ add_executable(Lab1CPP lab1.cpp) target_include_directories(Lab1CPP PUBLIC ../LibraryCPP) target_link_libraries(Lab1CPP LibraryCPP) -#add_test(NAME TestLab1CPP COMMAND Lab1CPP ${CMAKE_CURRENT_SOURCE_DIR}/input.txt) +add_test(NAME TestLab1CPP COMMAND Lab1CPP ${CMAKE_CURRENT_SOURCE_DIR}/input.txt) From eb3fc8ab06aa8aa2b0338c6223c0102f1e00db05 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 11 Sep 2024 13:46:39 +0300 Subject: [PATCH 17/73] Add files via upload --- Lab1CPP/lab1.cpp | 109 +++++++++++++++++++++++------------------------ 1 file changed, 53 insertions(+), 56 deletions(-) diff --git a/Lab1CPP/lab1.cpp b/Lab1CPP/lab1.cpp index 8040453060..2534f95423 100644 --- a/Lab1CPP/lab1.cpp +++ b/Lab1CPP/lab1.cpp @@ -1,57 +1,54 @@ -#include -#include -#include -#include "array.h" - -Data task_1(Array* array, size_t size) -{ - Data result = 0; - - array = create_random_array(size); - - for (int i = 1; i < array_size(array); i += 2) - { - if (array_get(array, i) > 0) - { - result += array_get(array, i); - } - } - return result; -} - -void task_2(Array* array, size_t size, Data a, Data b) -{ - array = create_random_array(size); - - for (int i = 0; i < array_size(array); i++) - { - if (array_get(array, i) >= a && array_get(array, i) <= b) - { - array_erase(array, i); - i--; - } - } -} - -int main() -{ - Array* arr = nullptr; - size_t size; - std::ifstream in("input.txt"); - if (in.is_open()) - { - in >> size; - task_1(arr, size); - array_delete(arr); - - Data a, b; - in >> size; - in >> a; - in >> b; - task_2(arr, size, a, b); - array_delete(arr); - } - in.close(); - - return 0; +#include "array.h" + +Data task_1(Array* array, size_t size) +{ + Data result = 0; + + array = create_random_array(size); + + for (size_t i = 1; i < array_size(array); i += 2) + { + if (array_get(array, i) > 0) + { + result += array_get(array, i); + } + } + return result; +} + +void task_2(Array* array, size_t size, Data a, Data b) +{ + array = create_random_array(size); + + for (size_t i = 0; i < array_size(array); i++) + { + if (array_get(array, i) >= a && array_get(array, i) <= b) + { + array_erase(array, i); + i--; + } + } +} + +int main() +{ + Array* arr = nullptr; + size_t size; + std::ifstream in("input.txt"); + if (in.is_open()) + { + in >> size; + task_1(arr, size); + array_delete(arr); + + Data a, b; + in >> size; + in >> a; + in >> b; + task_2(arr, size, a, b); + array_delete(arr); + } + in.close(); + + return 0; } \ No newline at end of file From b68f54c2f99284aaae89c549fe399a2c63515719 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 11 Sep 2024 13:47:35 +0300 Subject: [PATCH 18/73] Add files via upload --- LibraryCPP/CMakeLists.txt | 2 +- LibraryCPP/array.cpp | 14 ++++---------- LibraryCPP/array.h | 12 +++++------- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/LibraryCPP/CMakeLists.txt b/LibraryCPP/CMakeLists.txt index dbd7769feb..5437400078 100644 --- a/LibraryCPP/CMakeLists.txt +++ b/LibraryCPP/CMakeLists.txt @@ -1,3 +1,3 @@ -add_library(LibraryCPP STATIC array.cpp list.cpp queue.cpp stack.cpp vector.cpp) +add_library(LibraryCPP STATIC array.cpp) add_subdirectory(Tests) diff --git a/LibraryCPP/array.cpp b/LibraryCPP/array.cpp index c304419c32..6a6ea7580e 100644 --- a/LibraryCPP/array.cpp +++ b/LibraryCPP/array.cpp @@ -1,8 +1,4 @@ #include "array.h" -#include "time.h" - -typedef int Data; -typedef unsigned int size_t; struct Array { @@ -76,7 +72,7 @@ void array_erase(Array* arr, size_t index) } else { - for (int i = index; i < array_size(arr) - 1; i++) + for (size_t i = index; i < array_size(arr) - 1; i++) { arr->array[i] = arr->array[i + 1]; } @@ -87,14 +83,12 @@ void array_erase(Array* arr, size_t index) Array* create_random_array(Data size) { - srand(time(NULL)); - Array* arr = array_create(size); - for (int i = 0; i < size; i++) + for (Data i = 0; i < size; i++) { - Data value = rand() % (3 - 3 + 1) + 3; + Data value = i*15; array_set(arr, i, value); } return arr; -} +} \ No newline at end of file diff --git a/LibraryCPP/array.h b/LibraryCPP/array.h index a8d133eac4..e873aa0d54 100644 --- a/LibraryCPP/array.h +++ b/LibraryCPP/array.h @@ -1,9 +1,7 @@ #ifndef ARRAY_H #define ARRAY_H -#include #include -#include // Non-resizeable array // Stores integer values inside @@ -12,19 +10,19 @@ typedef int Data; struct Array; // create array -Array *array_create(size_t size); +Array* array_create(size_t size); // delete array, free memory -void array_delete(Array *arr); +void array_delete(Array* arr); // returns specified array element -Data array_get(const Array *arr, size_t index); +Data array_get(const Array* arr, size_t index); // sets the specified array element to the value -void array_set(Array *arr, size_t index, Data value); +void array_set(Array* arr, size_t index, Data value); // returns array size -size_t array_size(const Array *arr); +size_t array_size(const Array* arr); Array* create_random_array(Data size); From ccd9dca61bb2cdf6feac90bfb5c45aa5bd820b33 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 11 Sep 2024 13:48:02 +0300 Subject: [PATCH 19/73] Add files via upload --- CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index daa103b658..1707dde790 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,9 +10,5 @@ else() add_compile_options(-Wall -Wextra -Wpedantic -Wno-gnu-empty-struct -Wno-unused-parameter) endif() -#add_subdirectory(LibraryC) add_subdirectory(LibraryCPP) -#add_subdirectory(LibraryCPPClass) -#add_subdirectory(LibraryCPPTemplate) - add_subdirectory(Lab1CPP) From b2ac8dced93d9b1c6c2c8beb7ba3f911757ca42c Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 11 Sep 2024 13:52:16 +0300 Subject: [PATCH 20/73] Update array.cpp --- LibraryCPP/array.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LibraryCPP/array.cpp b/LibraryCPP/array.cpp index 6a6ea7580e..1a601ed494 100644 --- a/LibraryCPP/array.cpp +++ b/LibraryCPP/array.cpp @@ -64,7 +64,7 @@ size_t array_size(const Array* arr) void array_erase(Array* arr, size_t index) { - if (index >= 0 && index < arr->size) + if (index < arr->size) { if (index == arr->size - 1) { @@ -91,4 +91,4 @@ Array* create_random_array(Data size) array_set(arr, i, value); } return arr; -} \ No newline at end of file +} From a74eb684df423b723ff655919a9ff103c6c01e87 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 11 Sep 2024 13:55:28 +0300 Subject: [PATCH 21/73] Update array.h --- LibraryCPP/array.h | 1 + 1 file changed, 1 insertion(+) diff --git a/LibraryCPP/array.h b/LibraryCPP/array.h index e873aa0d54..46fe179f5a 100644 --- a/LibraryCPP/array.h +++ b/LibraryCPP/array.h @@ -2,6 +2,7 @@ #define ARRAY_H #include +#include // Non-resizeable array // Stores integer values inside From 14c22add0e4c8cb30945a8ff78411db782fad99d Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Thu, 12 Sep 2024 16:32:40 +0300 Subject: [PATCH 22/73] Update lab1.cpp --- Lab1CPP/lab1.cpp | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/Lab1CPP/lab1.cpp b/Lab1CPP/lab1.cpp index 2534f95423..a9329fec92 100644 --- a/Lab1CPP/lab1.cpp +++ b/Lab1CPP/lab1.cpp @@ -1,14 +1,15 @@ -#include "array.h" +#include "array.h" +#include -Data task_1(Array* array, size_t size) +Data task_1(Array*& array, std::ifstream& in) { Data result = 0; - array = create_random_array(size); + array = fill_array(in); - for (size_t i = 1; i < array_size(array); i += 2) + for (size_t i = 0; i < array_size(array); i++) { - if (array_get(array, i) > 0) + if (array_get(array, i) > 0 && array_get(array, i) % 2 == 0) { result += array_get(array, i); } @@ -16,39 +17,43 @@ Data task_1(Array* array, size_t size) return result; } -void task_2(Array* array, size_t size, Data a, Data b) +void task_2(Array*& array, std::ifstream& in) { - array = create_random_array(size); + array = fill_array(in); + + Data a, b; + in >> a >> b; + size_t k = 0; for (size_t i = 0; i < array_size(array); i++) { - if (array_get(array, i) >= a && array_get(array, i) <= b) + if (!(array_get(array, i) >= a && array_get(array, i) <= b)) { - array_erase(array, i); - i--; + if (i != k) + array_set(array, k, array_get(array, i)); + ++k; } } + + for (size_t i = k; i < array_size(array); i++) + array_set(array, i, 0); } int main() { - Array* arr = nullptr; - size_t size; std::ifstream in("input.txt"); if (in.is_open()) { - in >> size; - task_1(arr, size); + Array* arr = NULL; + + if (task_1(arr, in) != 30) + std::cout << "task_1 error result!" << std::endl; array_delete(arr); - Data a, b; - in >> size; - in >> a; - in >> b; - task_2(arr, size, a, b); + task_2(arr, in); array_delete(arr); } in.close(); return 0; -} \ No newline at end of file +} From 78c1f63b9d8aa19a20b4fe6e7ccf3f2b3e8fa20d Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Thu, 12 Sep 2024 16:33:03 +0300 Subject: [PATCH 23/73] Update input.txt --- Lab1CPP/input.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Lab1CPP/input.txt b/Lab1CPP/input.txt index de057f57a7..e2b3e97252 100644 --- a/Lab1CPP/input.txt +++ b/Lab1CPP/input.txt @@ -1,4 +1,5 @@ -5 10 +1 2 3 4 5 6 7 8 9 10 20 -40 +1 2 3 4 2 1 5 1 2 6 2 1 7 1 2 8 2 1 9 1 +4 10 From cfdb35d147c7f35e4ac8945312d3eba659eb7255 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Thu, 12 Sep 2024 16:33:47 +0300 Subject: [PATCH 24/73] Update array.cpp --- LibraryCPP/array.cpp | 53 +++++++++++++------------------------------- 1 file changed, 16 insertions(+), 37 deletions(-) diff --git a/LibraryCPP/array.cpp b/LibraryCPP/array.cpp index 1a601ed494..4ada007600 100644 --- a/LibraryCPP/array.cpp +++ b/LibraryCPP/array.cpp @@ -23,13 +23,10 @@ Array* array_create(size_t size) // delete array, free memory void array_delete(Array* arr) { - if (arr != nullptr) + if (arr->array != nullptr) { - if (arr->array != nullptr) - { - delete[] arr->array; - delete arr; - } + delete[] arr->array; + delete arr; } } @@ -54,41 +51,23 @@ void array_set(Array* arr, size_t index, Data value) // returns array size size_t array_size(const Array* arr) { - if (arr != nullptr) - { - if (arr->array != nullptr) - return arr->size; - } + if (arr->array != nullptr) + return arr->size; return 0; } -void array_erase(Array* arr, size_t index) -{ - if (index < arr->size) - { - if (index == arr->size - 1) - { - arr->array[index] = 0; - } - else - { - for (size_t i = index; i < array_size(arr) - 1; i++) - { - arr->array[i] = arr->array[i + 1]; - } - arr->array[arr->size - 1] = 0; - } - } -} - -Array* create_random_array(Data size) +// fill array from file +Array* fill_array(std::ifstream &in) { - Array* arr = array_create(size); - - for (Data i = 0; i < size; i++) + size_t size; + Data value; + in >> size; + Array* array = array_create(size); + for (int i = 0; i < size; i++) { - Data value = i*15; - array_set(arr, i, value); + in >> value; + array_set(array, i, value); } - return arr; + + return array; } From 5edd363961a76d9f376889d49085190d3cd66c91 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Thu, 12 Sep 2024 16:34:07 +0300 Subject: [PATCH 25/73] Update array.h --- LibraryCPP/array.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/LibraryCPP/array.h b/LibraryCPP/array.h index 46fe179f5a..3b61df7ef5 100644 --- a/LibraryCPP/array.h +++ b/LibraryCPP/array.h @@ -2,6 +2,7 @@ #define ARRAY_H #include +#include #include // Non-resizeable array @@ -25,8 +26,7 @@ void array_set(Array* arr, size_t index, Data value); // returns array size size_t array_size(const Array* arr); -Array* create_random_array(Data size); - -void array_erase(Array* arr, size_t index); +// fill array from file +Array* fill_array(std::ifstream &in); #endif From 2df541614e551670d990a2a137cc4c3cc4f1f070 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Thu, 12 Sep 2024 16:36:17 +0300 Subject: [PATCH 26/73] Update array.cpp --- LibraryCPP/array.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LibraryCPP/array.cpp b/LibraryCPP/array.cpp index 4ada007600..fc0377198f 100644 --- a/LibraryCPP/array.cpp +++ b/LibraryCPP/array.cpp @@ -63,7 +63,7 @@ Array* fill_array(std::ifstream &in) Data value; in >> size; Array* array = array_create(size); - for (int i = 0; i < size; i++) + for (size_t i = 0; i < size; i++) { in >> value; array_set(array, i, value); From 98cbf4f39a8b4a9af84ed8d444476dd08fea7fcf Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:12:37 +0300 Subject: [PATCH 27/73] Add files via upload --- LibraryCPP/list.cpp | 83 ++++++++++++++++++++++++++++++++++++++------ LibraryCPP/stack.cpp | 24 ++++++++++--- 2 files changed, 91 insertions(+), 16 deletions(-) diff --git a/LibraryCPP/list.cpp b/LibraryCPP/list.cpp index a8946b5793..f9cf858f3c 100644 --- a/LibraryCPP/list.cpp +++ b/LibraryCPP/list.cpp @@ -3,59 +3,120 @@ struct ListItem { + Data value; + ListItem* next = nullptr; + ListItem* prev = nullptr; }; struct List { + ListItem* node = nullptr; }; List *list_create() { - return new List; + List* newList = new List(nullptr); + return newList; } void list_delete(List *list) { - // TODO: free items - delete list; + if (list != nullptr) + { + while (list->node != nullptr) + { + ListItem* curr = list->node->next; + list->node = list->node->next; + delete curr; + } + + delete list; + } } ListItem *list_first(List *list) { - return NULL; + if (list != nullptr) + return list->node; } Data list_item_data(const ListItem *item) { - return (Data)0; + if (item != nullptr) + return item->value; } ListItem *list_item_next(ListItem *item) { - return NULL; + if(item != nullptr && item->next != nullptr) + return item->next; + return nullptr; } ListItem *list_item_prev(ListItem *item) { - return NULL; + if (item != nullptr && item->prev != nullptr) + return item->prev; + return nullptr; } -ListItem *list_insert(List *list, Data data) +ListItem* list_insert(List* list, Data data) { - return NULL; + ListItem* newEl = new ListItem; + newEl->value = data; + newEl->prev = nullptr; + + if (list->node != nullptr) + newEl->next = list->node; + else + newEl->next = nullptr; + + list->node = newEl; + + return newEl; } ListItem *list_insert_after(List *list, ListItem *item, Data data) { - return NULL; + if (list != nullptr && item != nullptr) + { + ListItem* newEl = new ListItem; + newEl->value = data; + newEl->prev = item; + + if(item->next != nullptr) + newEl->next = item->next; + + item->next = newEl; + + return newEl; + } + + return nullptr; } ListItem *list_erase_first(List *list) { + if (list != nullptr && list->node != nullptr) + { + ListItem* temp = list->node->next; + temp->prev = nullptr; + delete list->node; + list->node = temp; + + return list->node; + } return NULL; } ListItem *list_erase_next(List *list, ListItem *item) { - return NULL; + if (list != nullptr && item != nullptr && item->next != nullptr) + { + item->next->next->prev = item; + ListItem* temp = item->next->next; + delete item->next; + item->next = temp; + } + return temp; } diff --git a/LibraryCPP/stack.cpp b/LibraryCPP/stack.cpp index c090abba1c..a3c5d97171 100644 --- a/LibraryCPP/stack.cpp +++ b/LibraryCPP/stack.cpp @@ -2,33 +2,47 @@ struct Stack { + List* list = nullptr; }; Stack *stack_create() { - return new Stack; + Stack* stack = new Stack; + stack->list = list_create(); + + return stack; } void stack_delete(Stack *stack) { - // TODO: free stack elements - delete stack; + if(stack != nullptr) + list_delete(stack->list); } void stack_push(Stack *stack, Data data) { + if(stack != nullptr) + list_insert(stack->list, data); } Data stack_get(const Stack *stack) { - return (Data)0; + if(stack != nullptr) + return list_item_data(list_first(stack->list)); } void stack_pop(Stack *stack) { + if(stack != nullptr) + list_erase_first(stack->list); } bool stack_empty(const Stack *stack) { - return true; + if (stack != nullptr) + { + if (list_first(stack->list) == nullptr) + return true; + return false; + } } From 6f1530233caf04e8749d77b2ebaa1cac1dcf0eb3 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:14:42 +0300 Subject: [PATCH 28/73] Create 1 --- Lab2CPP/1 | 1 + 1 file changed, 1 insertion(+) create mode 100644 Lab2CPP/1 diff --git a/Lab2CPP/1 b/Lab2CPP/1 new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Lab2CPP/1 @@ -0,0 +1 @@ +1 From 1e0264036b468531913055d60803f2bb09bac2c9 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:17:11 +0300 Subject: [PATCH 29/73] Add files via upload --- Lab2CPP/CMakeLists .txt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Lab2CPP/CMakeLists .txt diff --git a/Lab2CPP/CMakeLists .txt b/Lab2CPP/CMakeLists .txt new file mode 100644 index 0000000000..47b2797050 --- /dev/null +++ b/Lab2CPP/CMakeLists .txt @@ -0,0 +1,5 @@ +add_executable(Lab2CPP lab2.cpp) +target_include_directories(Lab2CPP PUBLIC ../LibraryCPP) +target_link_libraries(Lab2CPP LibraryCPP) + +#add_test(NAME TestLab2CPP COMMAND Lab1CPP ${CMAKE_CURRENT_SOURCE_DIR}/input.txt) From e5d8c4533147326c29cfd00ee48bc5ee6865f0e1 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:18:59 +0300 Subject: [PATCH 30/73] Add files via upload --- LibraryCPP/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LibraryCPP/CMakeLists.txt b/LibraryCPP/CMakeLists.txt index 5437400078..607f6546ac 100644 --- a/LibraryCPP/CMakeLists.txt +++ b/LibraryCPP/CMakeLists.txt @@ -1,3 +1,3 @@ -add_library(LibraryCPP STATIC array.cpp) +add_library(LibraryCPP STATIC list.cpp stack.cpp) add_subdirectory(Tests) From 70cb6b9317b34e6f8fd6fa57b76ec034a4dad8d2 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:19:33 +0300 Subject: [PATCH 31/73] Update CMakeLists.txt --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1707dde790..8939021ea1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,4 +11,4 @@ else() endif() add_subdirectory(LibraryCPP) -add_subdirectory(Lab1CPP) +add_subdirectory(Lab2CPP) From 09ed8ef4af5f197e67e83e0f63bbddfa2a2a8c81 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:27:30 +0300 Subject: [PATCH 32/73] Create lab2.cpp --- Lab2CPP/lab2.cpp | 1 + 1 file changed, 1 insertion(+) create mode 100644 Lab2CPP/lab2.cpp diff --git a/Lab2CPP/lab2.cpp b/Lab2CPP/lab2.cpp new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/Lab2CPP/lab2.cpp @@ -0,0 +1 @@ + From 0264cadf278e86cfbfaed850e484a9378083eb50 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:28:03 +0300 Subject: [PATCH 33/73] Delete Lab2CPP/1 --- Lab2CPP/1 | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Lab2CPP/1 diff --git a/Lab2CPP/1 b/Lab2CPP/1 deleted file mode 100644 index d00491fd7e..0000000000 --- a/Lab2CPP/1 +++ /dev/null @@ -1 +0,0 @@ -1 From 6adbe176d771e6ff622bff8aed57d938dcb004a3 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:29:06 +0300 Subject: [PATCH 34/73] Update lab2.cpp --- Lab2CPP/lab2.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Lab2CPP/lab2.cpp b/Lab2CPP/lab2.cpp index 8b13789179..1e736a6480 100644 --- a/Lab2CPP/lab2.cpp +++ b/Lab2CPP/lab2.cpp @@ -1 +1,7 @@ +#include "stack.h" +int main() +{ + + return 0; +} From b7dac417b64c2028ba1c9a49f21df3fe84cf5d1f Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:30:58 +0300 Subject: [PATCH 35/73] Rename CMakeLists .txt to CMakeLists.txt --- Lab2CPP/{CMakeLists .txt => CMakeLists.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Lab2CPP/{CMakeLists .txt => CMakeLists.txt} (100%) diff --git a/Lab2CPP/CMakeLists .txt b/Lab2CPP/CMakeLists.txt similarity index 100% rename from Lab2CPP/CMakeLists .txt rename to Lab2CPP/CMakeLists.txt From 535e8391ac74e57781f47137fcd4ba7a877cb540 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:35:20 +0300 Subject: [PATCH 36/73] Update list.cpp --- LibraryCPP/list.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/LibraryCPP/list.cpp b/LibraryCPP/list.cpp index f9cf858f3c..97621583b2 100644 --- a/LibraryCPP/list.cpp +++ b/LibraryCPP/list.cpp @@ -15,7 +15,7 @@ struct List List *list_create() { - List* newList = new List(nullptr); + List* newList = new List; return newList; } @@ -38,12 +38,14 @@ ListItem *list_first(List *list) { if (list != nullptr) return list->node; + return nullptr; } Data list_item_data(const ListItem *item) { if (item != nullptr) return item->value; + return nullptr; } ListItem *list_item_next(ListItem *item) @@ -117,6 +119,6 @@ ListItem *list_erase_next(List *list, ListItem *item) ListItem* temp = item->next->next; delete item->next; item->next = temp; + return temp; } - return temp; } From cdab2695f0ebcaa7ce8a6efc781f22fdbb562c3b Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:39:36 +0300 Subject: [PATCH 37/73] Update list.cpp --- LibraryCPP/list.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/LibraryCPP/list.cpp b/LibraryCPP/list.cpp index 97621583b2..f0c49c27ba 100644 --- a/LibraryCPP/list.cpp +++ b/LibraryCPP/list.cpp @@ -45,7 +45,7 @@ Data list_item_data(const ListItem *item) { if (item != nullptr) return item->value; - return nullptr; + return (Data)0; } ListItem *list_item_next(ListItem *item) @@ -121,4 +121,6 @@ ListItem *list_erase_next(List *list, ListItem *item) item->next = temp; return temp; } + + return temp; } From 26b451e5148e50c655646f6fc56230eb1d9ed5a8 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:42:03 +0300 Subject: [PATCH 38/73] Update list.cpp --- LibraryCPP/list.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LibraryCPP/list.cpp b/LibraryCPP/list.cpp index f0c49c27ba..fcd4010de5 100644 --- a/LibraryCPP/list.cpp +++ b/LibraryCPP/list.cpp @@ -122,5 +122,5 @@ ListItem *list_erase_next(List *list, ListItem *item) return temp; } - return temp; + return nullptr; } From bd28b9a727e3b04ba34438a07220dc3f9517d046 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 18 Sep 2024 17:00:04 +0300 Subject: [PATCH 39/73] Update stack.h --- LibraryCPP/stack.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LibraryCPP/stack.h b/LibraryCPP/stack.h index 7c5dd97af2..fedc0ad151 100644 --- a/LibraryCPP/stack.h +++ b/LibraryCPP/stack.h @@ -1,6 +1,6 @@ #ifndef STACK_H #define STACK_H - +#include "list.h" // Stack // Stores integer values inside typedef int Data; From d526cb251b81531d9fd7d59434a1f29377c3cd10 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 18 Sep 2024 19:09:05 +0300 Subject: [PATCH 40/73] Update stack.cpp --- LibraryCPP/stack.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/LibraryCPP/stack.cpp b/LibraryCPP/stack.cpp index a3c5d97171..6a52c76a48 100644 --- a/LibraryCPP/stack.cpp +++ b/LibraryCPP/stack.cpp @@ -29,6 +29,7 @@ Data stack_get(const Stack *stack) { if(stack != nullptr) return list_item_data(list_first(stack->list)); + return (Data)0; } void stack_pop(Stack *stack) @@ -45,4 +46,5 @@ bool stack_empty(const Stack *stack) return true; return false; } + return true; } From e346e9cc806bd294438aad084a205defb88099b2 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 18 Sep 2024 19:11:26 +0300 Subject: [PATCH 41/73] Update CMakeLists.txt --- LibraryCPP/Tests/CMakeLists.txt | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/LibraryCPP/Tests/CMakeLists.txt b/LibraryCPP/Tests/CMakeLists.txt index 98d8c01fd6..d871c096be 100644 --- a/LibraryCPP/Tests/CMakeLists.txt +++ b/LibraryCPP/Tests/CMakeLists.txt @@ -1,12 +1,12 @@ -add_executable(TestArrayCPP array.cpp) -target_include_directories(TestArrayCPP PUBLIC ..) -target_link_libraries(TestArrayCPP LibraryCPP) -add_test(TestArrayCPP TestArrayCPP) +#add_executable(TestArrayCPP array.cpp) +#target_include_directories(TestArrayCPP PUBLIC ..) +#target_link_libraries(TestArrayCPP LibraryCPP) +#add_test(TestArrayCPP TestArrayCPP) -# add_executable(TestListCPP list.cpp) -# target_include_directories(TestListCPP PUBLIC ..) -# target_link_libraries(TestListCPP LibraryCPP) -# add_test(TestListCPP TestListCPP) +add_executable(TestListCPP list.cpp) +target_include_directories(TestListCPP PUBLIC ..) +target_link_libraries(TestListCPP LibraryCPP) +add_test(TestListCPP TestListCPP) # add_executable(TestQueueCPP queue.cpp) # target_include_directories(TestQueueCPP PUBLIC ..) @@ -14,10 +14,10 @@ add_test(TestArrayCPP TestArrayCPP) # add_test(TestQueueCPP TestQueueCPP) # set_tests_properties(TestQueueCPP PROPERTIES TIMEOUT 10) -# add_executable(TestStackCPP stack.cpp) -# target_include_directories(TestStackCPP PUBLIC ..) -# target_link_libraries(TestStackCPP LibraryCPP) -# add_test(TestStackCPP TestStackCPP) +add_executable(TestStackCPP stack.cpp) +target_include_directories(TestStackCPP PUBLIC ..) +target_link_libraries(TestStackCPP LibraryCPP) +add_test(TestStackCPP TestStackCPP) # add_executable(TestVectorCPP vector.cpp) # target_include_directories(TestVectorCPP PUBLIC ..) From fb6564c49e5b91a40546a9fa6d6fde67dc8f4268 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 18 Sep 2024 19:48:12 +0300 Subject: [PATCH 42/73] Update list.cpp --- LibraryCPP/list.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/LibraryCPP/list.cpp b/LibraryCPP/list.cpp index fcd4010de5..59b64a1162 100644 --- a/LibraryCPP/list.cpp +++ b/LibraryCPP/list.cpp @@ -19,21 +19,22 @@ List *list_create() return newList; } -void list_delete(List *list) +void list_delete(List* list) { if (list != nullptr) { - while (list->node != nullptr) + ListItem* current = list->node; + while (current != nullptr) { - ListItem* curr = list->node->next; - list->node = list->node->next; - delete curr; + ListItem* next = current->next; + delete current; + current = next; } - delete list; } } + ListItem *list_first(List *list) { if (list != nullptr) From 27c441c2748ecff6b79d45f15dd2113dd6e5d2cf Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 18 Sep 2024 19:55:20 +0300 Subject: [PATCH 43/73] Update stack.cpp --- LibraryCPP/Tests/stack.cpp | 143 +++++++++++++++++++++++++++---------- 1 file changed, 107 insertions(+), 36 deletions(-) diff --git a/LibraryCPP/Tests/stack.cpp b/LibraryCPP/Tests/stack.cpp index 0fac2b5813..7af1761081 100644 --- a/LibraryCPP/Tests/stack.cpp +++ b/LibraryCPP/Tests/stack.cpp @@ -1,57 +1,128 @@ -#include -#include "stack.h" +#include +#include "list.h" -int main() +struct ListItem { - Stack *stack = stack_create(); + Data value; + ListItem* next = nullptr; + ListItem* prev = nullptr; +}; - stack_push(stack, 1); - stack_push(stack, 2); - stack_push(stack, 3); +struct List +{ + ListItem* node = nullptr; +}; - if (stack_get(stack) != 3) +List *list_create() +{ + List* newList = new List; + return newList; +} + +void list_delete(List* list) +{ + if (list != nullptr) { - std::cout << "Invalid stack top after push\n"; - stack_delete(stack); - return 1; + ListItem* current = list->node; + while (current != nullptr) + { + ListItem* next = current->next; + delete current; + current = next; + } + delete list; } +} - std::cout << "Get: " << stack_get(stack) << "\n"; - stack_pop(stack); - if (stack_get(stack) != 2) - { - std::cout << "Invalid stack top after pop\n"; - stack_delete(stack); - return 1; - } +ListItem *list_first(List *list) +{ + if (list != nullptr) + return list->node; + return nullptr; +} + +Data list_item_data(const ListItem *item) +{ + if (item != nullptr) + return item->value; + return (Data)0; +} - std::cout << "Get: " << stack_get(stack) << "\n"; - stack_pop(stack); +ListItem *list_item_next(ListItem *item) +{ + if(item != nullptr && item->next != nullptr) + return item->next; + return nullptr; +} - if (stack_get(stack) != 1) +ListItem *list_item_prev(ListItem *item) +{ + if (item != nullptr && item->prev != nullptr) + return item->prev; + return nullptr; +} + +ListItem* list_insert(List* list, Data data) +{ + ListItem* newEl = new ListItem; + newEl->value = data; + newEl->prev = nullptr; + + if (list->node != nullptr) + newEl->next = list->node; + else + newEl->next = nullptr; + + list->node = newEl; + + return newEl; +} + +ListItem *list_insert_after(List *list, ListItem *item, Data data) +{ + if (list != nullptr && item != nullptr) { - std::cout << "Invalid stack top after pop\n"; - stack_delete(stack); - return 1; + ListItem* newEl = new ListItem; + newEl->value = data; + newEl->prev = item; + + if(item->next != nullptr) + newEl->next = item->next; + + item->next = newEl; + + return newEl; } - std::cout << "Get: " << stack_get(stack) << "\n"; - stack_push(stack, 4); - stack_push(stack, 5); + return nullptr; +} - if (stack_get(stack) != 5) +ListItem *list_erase_first(List *list) +{ + if (list != nullptr && list->node != nullptr) { - std::cout << "Invalid stack top after push\n"; - stack_delete(stack); - return 1; + ListItem* temp = list->node->next; + if(temp != nullptr) + temp->prev = nullptr; + delete list->node; + list->node = temp; + + return list->node; } + return NULL; +} - while (!stack_empty(stack)) +ListItem *list_erase_next(List *list, ListItem *item) +{ + if (list != nullptr && item != nullptr && item->next != nullptr) { - std::cout << "Get: " << stack_get(stack) << "\n"; - stack_pop(stack); + item->next->next->prev = item; + ListItem* temp = item->next->next; + delete item->next; + item->next = temp; + return temp; } - stack_delete(stack); + return nullptr; } From e287c5107aad985845c42af2f1811300abe37d43 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Mon, 23 Sep 2024 13:46:59 +0300 Subject: [PATCH 44/73] Delete Lab1CPP directory --- Lab1CPP/CMakeLists.txt | 5 ---- Lab1CPP/input.txt | 5 ---- Lab1CPP/lab1.cpp | 59 ------------------------------------------ 3 files changed, 69 deletions(-) delete mode 100644 Lab1CPP/CMakeLists.txt delete mode 100644 Lab1CPP/input.txt delete mode 100644 Lab1CPP/lab1.cpp diff --git a/Lab1CPP/CMakeLists.txt b/Lab1CPP/CMakeLists.txt deleted file mode 100644 index 8ff312b8be..0000000000 --- a/Lab1CPP/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -add_executable(Lab1CPP lab1.cpp) -target_include_directories(Lab1CPP PUBLIC ../LibraryCPP) -target_link_libraries(Lab1CPP LibraryCPP) - -add_test(NAME TestLab1CPP COMMAND Lab1CPP ${CMAKE_CURRENT_SOURCE_DIR}/input.txt) diff --git a/Lab1CPP/input.txt b/Lab1CPP/input.txt deleted file mode 100644 index e2b3e97252..0000000000 --- a/Lab1CPP/input.txt +++ /dev/null @@ -1,5 +0,0 @@ -10 -1 2 3 4 5 6 7 8 9 10 -20 -1 2 3 4 2 1 5 1 2 6 2 1 7 1 2 8 2 1 9 1 -4 10 diff --git a/Lab1CPP/lab1.cpp b/Lab1CPP/lab1.cpp deleted file mode 100644 index a9329fec92..0000000000 --- a/Lab1CPP/lab1.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include "array.h" -#include - -Data task_1(Array*& array, std::ifstream& in) -{ - Data result = 0; - - array = fill_array(in); - - for (size_t i = 0; i < array_size(array); i++) - { - if (array_get(array, i) > 0 && array_get(array, i) % 2 == 0) - { - result += array_get(array, i); - } - } - return result; -} - -void task_2(Array*& array, std::ifstream& in) -{ - array = fill_array(in); - - Data a, b; - in >> a >> b; - - size_t k = 0; - for (size_t i = 0; i < array_size(array); i++) - { - if (!(array_get(array, i) >= a && array_get(array, i) <= b)) - { - if (i != k) - array_set(array, k, array_get(array, i)); - ++k; - } - } - - for (size_t i = k; i < array_size(array); i++) - array_set(array, i, 0); -} - -int main() -{ - std::ifstream in("input.txt"); - if (in.is_open()) - { - Array* arr = NULL; - - if (task_1(arr, in) != 30) - std::cout << "task_1 error result!" << std::endl; - array_delete(arr); - - task_2(arr, in); - array_delete(arr); - } - in.close(); - - return 0; -} From 8f7e77a6bb9913bf0b55f1645cefeadeb64a19ef Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Mon, 23 Sep 2024 14:00:05 +0300 Subject: [PATCH 45/73] Update lab2.cpp --- Lab2CPP/lab2.cpp | 132 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 130 insertions(+), 2 deletions(-) diff --git a/Lab2CPP/lab2.cpp b/Lab2CPP/lab2.cpp index 1e736a6480..9bf8ca247f 100644 --- a/Lab2CPP/lab2.cpp +++ b/Lab2CPP/lab2.cpp @@ -1,7 +1,135 @@ +#include +#include +#include #include "stack.h" + +unsigned int priority(const char symbol) +{ + if (symbol == '*' || symbol == '/') + return 3; + if (symbol == '+' || symbol == '-') + return 2; + if (symbol == '(') + return 1; + + return 0; +} + +std::string RPN(std::string data) +{ + Stack* stack = stack_create(); + std::string res = ""; + for (size_t i = 0; i < data.size(); i++) + { + if (isdigit(data[i])) + { + res += data[i]; + } + else + { + if (data[i] == '(') + { + stack_push(stack, data[i]); + } + else if (data[i] == ')') + { + while (!stack_empty(stack) && stack_get(stack) != '(') + { + res += stack_get(stack); + stack_pop(stack); + } + if (!stack_empty(stack) && stack_get(stack) == '(') + { + stack_pop(stack); + } + } + else + { + while (!stack_empty(stack) && priority(stack_get(stack)) >= priority(data[i])) + { + res += stack_get(stack); + stack_pop(stack); + } + stack_push(stack, data[i]); + } + } + } + + while (!stack_empty(stack)) + { + res += stack_get(stack); + stack_pop(stack); + } + + stack_delete(stack); + return res; +} + +Data solve(std::string data) +{ + Stack* stack = stack_create(); + for (size_t i = 0; i < data.size(); i++) + { + if (isdigit(data[i])) + stack_push(stack, data[i] - '0'); + else + { + Data val1 = stack_get(stack); + stack_pop(stack); + Data val2 = stack_get(stack); + stack_pop(stack); + Data res = 0; + + switch (data[i]) + { + case '+': res = val1 + val2; + break; + case '-': res = val1 - val2; + break; + case '*': res = val1 * val2; + break; + case '/': res = val1 / val2; + break; + } + + stack_push(stack, res); + } + } + + Data res = stack_get(stack); + stack_delete(stack); + return res; +} + +std::string calculate(std::string expr) +{ + expr = RPN(expr); + expr = std::to_string(solve(expr)); + + return expr; +} + int main() { - - return 0; + std::ifstream in("input.txt"); + + std::string temp = "", check = ""; + in >> temp; + in >> check; + temp = calculate(temp); + if (temp != check) + { + std::cout << "Test1. Incorrect answer!" << std::endl; + } + + in >> temp; + in >> check; + temp = calculate(temp); + if (temp != check) + { + std::cout << "Test2. Incorrect answer!" << std::endl; + } + + return 0; } From 0d677f982cfb569cb444ab784de6ce209799a382 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Mon, 23 Sep 2024 14:00:36 +0300 Subject: [PATCH 46/73] Add files via upload --- Lab2CPP/input.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Lab2CPP/input.txt diff --git a/Lab2CPP/input.txt b/Lab2CPP/input.txt new file mode 100644 index 0000000000..8edcedd1dd --- /dev/null +++ b/Lab2CPP/input.txt @@ -0,0 +1,4 @@ +(1+2)*3 +9 +1+2*3 +7 \ No newline at end of file From 4daacc0c647eba33329f84e1b003e28f3830bcdb Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Mon, 23 Sep 2024 14:05:50 +0300 Subject: [PATCH 47/73] Update stack.cpp From 8ad0d1ad4f7e877bc2efe1f8d826b39377ffeb99 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Mon, 23 Sep 2024 14:06:09 +0300 Subject: [PATCH 48/73] Update list.cpp --- LibraryCPP/list.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/LibraryCPP/list.cpp b/LibraryCPP/list.cpp index 59b64a1162..9f2b447197 100644 --- a/LibraryCPP/list.cpp +++ b/LibraryCPP/list.cpp @@ -3,7 +3,7 @@ struct ListItem { - Data value; + Data value = NULL; ListItem* next = nullptr; ListItem* prev = nullptr; }; @@ -103,7 +103,8 @@ ListItem *list_erase_first(List *list) if (list != nullptr && list->node != nullptr) { ListItem* temp = list->node->next; - temp->prev = nullptr; + if(temp != nullptr) + temp->prev = nullptr; delete list->node; list->node = temp; From ad26d88bb308e55201907299a1237fa9630a7550 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Mon, 23 Sep 2024 14:07:16 +0300 Subject: [PATCH 49/73] Update stack.cpp --- LibraryCPP/Tests/stack.cpp | 143 ++++++++++--------------------------- 1 file changed, 36 insertions(+), 107 deletions(-) diff --git a/LibraryCPP/Tests/stack.cpp b/LibraryCPP/Tests/stack.cpp index 7af1761081..0fac2b5813 100644 --- a/LibraryCPP/Tests/stack.cpp +++ b/LibraryCPP/Tests/stack.cpp @@ -1,128 +1,57 @@ -#include -#include "list.h" +#include +#include "stack.h" -struct ListItem +int main() { - Data value; - ListItem* next = nullptr; - ListItem* prev = nullptr; -}; + Stack *stack = stack_create(); -struct List -{ - ListItem* node = nullptr; -}; + stack_push(stack, 1); + stack_push(stack, 2); + stack_push(stack, 3); -List *list_create() -{ - List* newList = new List; - return newList; -} - -void list_delete(List* list) -{ - if (list != nullptr) + if (stack_get(stack) != 3) { - ListItem* current = list->node; - while (current != nullptr) - { - ListItem* next = current->next; - delete current; - current = next; - } - delete list; + std::cout << "Invalid stack top after push\n"; + stack_delete(stack); + return 1; } -} - -ListItem *list_first(List *list) -{ - if (list != nullptr) - return list->node; - return nullptr; -} + std::cout << "Get: " << stack_get(stack) << "\n"; + stack_pop(stack); -Data list_item_data(const ListItem *item) -{ - if (item != nullptr) - return item->value; - return (Data)0; -} - -ListItem *list_item_next(ListItem *item) -{ - if(item != nullptr && item->next != nullptr) - return item->next; - return nullptr; -} - -ListItem *list_item_prev(ListItem *item) -{ - if (item != nullptr && item->prev != nullptr) - return item->prev; - return nullptr; -} - -ListItem* list_insert(List* list, Data data) -{ - ListItem* newEl = new ListItem; - newEl->value = data; - newEl->prev = nullptr; - - if (list->node != nullptr) - newEl->next = list->node; - else - newEl->next = nullptr; - - list->node = newEl; - - return newEl; -} - -ListItem *list_insert_after(List *list, ListItem *item, Data data) -{ - if (list != nullptr && item != nullptr) + if (stack_get(stack) != 2) { - ListItem* newEl = new ListItem; - newEl->value = data; - newEl->prev = item; - - if(item->next != nullptr) - newEl->next = item->next; + std::cout << "Invalid stack top after pop\n"; + stack_delete(stack); + return 1; + } - item->next = newEl; + std::cout << "Get: " << stack_get(stack) << "\n"; + stack_pop(stack); - return newEl; + if (stack_get(stack) != 1) + { + std::cout << "Invalid stack top after pop\n"; + stack_delete(stack); + return 1; } - return nullptr; -} + std::cout << "Get: " << stack_get(stack) << "\n"; + stack_push(stack, 4); + stack_push(stack, 5); -ListItem *list_erase_first(List *list) -{ - if (list != nullptr && list->node != nullptr) + if (stack_get(stack) != 5) { - ListItem* temp = list->node->next; - if(temp != nullptr) - temp->prev = nullptr; - delete list->node; - list->node = temp; - - return list->node; + std::cout << "Invalid stack top after push\n"; + stack_delete(stack); + return 1; } - return NULL; -} -ListItem *list_erase_next(List *list, ListItem *item) -{ - if (list != nullptr && item != nullptr && item->next != nullptr) + while (!stack_empty(stack)) { - item->next->next->prev = item; - ListItem* temp = item->next->next; - delete item->next; - item->next = temp; - return temp; + std::cout << "Get: " << stack_get(stack) << "\n"; + stack_pop(stack); } - return nullptr; + stack_delete(stack); } From 6f287e71cd27a3917b85107df0a02518812da083 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Mon, 23 Sep 2024 14:10:36 +0300 Subject: [PATCH 50/73] Update list.cpp --- LibraryCPP/list.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LibraryCPP/list.cpp b/LibraryCPP/list.cpp index 9f2b447197..7af1761081 100644 --- a/LibraryCPP/list.cpp +++ b/LibraryCPP/list.cpp @@ -3,7 +3,7 @@ struct ListItem { - Data value = NULL; + Data value; ListItem* next = nullptr; ListItem* prev = nullptr; }; From b39aaa83e8bbfa7b12a9a7a28ded5ed1f72c54da Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:16:28 +0300 Subject: [PATCH 51/73] Update CMakeLists.txt --- Lab2CPP/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lab2CPP/CMakeLists.txt b/Lab2CPP/CMakeLists.txt index 47b2797050..ec593b4476 100644 --- a/Lab2CPP/CMakeLists.txt +++ b/Lab2CPP/CMakeLists.txt @@ -2,4 +2,4 @@ add_executable(Lab2CPP lab2.cpp) target_include_directories(Lab2CPP PUBLIC ../LibraryCPP) target_link_libraries(Lab2CPP LibraryCPP) -#add_test(NAME TestLab2CPP COMMAND Lab1CPP ${CMAKE_CURRENT_SOURCE_DIR}/input.txt) +add_test(NAME TestLab2CPP COMMAND Lab2CPP ${CMAKE_CURRENT_SOURCE_DIR}/input.txt) From 058efc71a4df7a9a0e93399980c17ab0695a6af6 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:19:41 +0300 Subject: [PATCH 52/73] Update lab2.cpp --- Lab2CPP/lab2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lab2CPP/lab2.cpp b/Lab2CPP/lab2.cpp index 9bf8ca247f..939c63c9f0 100644 --- a/Lab2CPP/lab2.cpp +++ b/Lab2CPP/lab2.cpp @@ -130,6 +130,6 @@ int main() { std::cout << "Test2. Incorrect answer!" << std::endl; } - + in.close(); return 0; } From 673012507bedd1f814bddd1920302978624886a5 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:22:08 +0300 Subject: [PATCH 53/73] Update stack.cpp --- LibraryCPP/stack.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/LibraryCPP/stack.cpp b/LibraryCPP/stack.cpp index 6a52c76a48..a0fc65b73b 100644 --- a/LibraryCPP/stack.cpp +++ b/LibraryCPP/stack.cpp @@ -17,6 +17,7 @@ void stack_delete(Stack *stack) { if(stack != nullptr) list_delete(stack->list); + delete stack; } void stack_push(Stack *stack, Data data) From 8e4a69615b8bb16a6ba6ac20dd6c57810ffcd86c Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 25 Sep 2024 16:29:56 +0300 Subject: [PATCH 54/73] Update lab2.cpp --- Lab2CPP/lab2.cpp | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/Lab2CPP/lab2.cpp b/Lab2CPP/lab2.cpp index 939c63c9f0..54cec2478a 100644 --- a/Lab2CPP/lab2.cpp +++ b/Lab2CPP/lab2.cpp @@ -3,7 +3,6 @@ #include #include "stack.h" - unsigned int priority(const char symbol) { if (symbol == '*' || symbol == '/') @@ -114,22 +113,13 @@ int main() { std::ifstream in("input.txt"); - std::string temp = "", check = ""; + std::string temp = ""; in >> temp; - in >> check; - temp = calculate(temp); - if (temp != check) - { - std::cout << "Test1. Incorrect answer!" << std::endl; - } - + std::cout << temp << " = " << calculate(temp); + in >> temp; - in >> check; - temp = calculate(temp); - if (temp != check) - { - std::cout << "Test2. Incorrect answer!" << std::endl; - } + std::cout << temp << " = " << calculate(temp); + in.close(); return 0; } From 69bb0b847b1d29678985685d8d6dbd395230dea4 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 25 Sep 2024 16:30:12 +0300 Subject: [PATCH 55/73] Update input.txt --- Lab2CPP/input.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/Lab2CPP/input.txt b/Lab2CPP/input.txt index 8edcedd1dd..23cd4180d8 100644 --- a/Lab2CPP/input.txt +++ b/Lab2CPP/input.txt @@ -1,4 +1,2 @@ (1+2)*3 -9 1+2*3 -7 \ No newline at end of file From 0eb16622530d3ca02f3c25acbf1cfbc31297e819 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 25 Sep 2024 16:30:39 +0300 Subject: [PATCH 56/73] Update list.cpp --- LibraryCPP/list.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/LibraryCPP/list.cpp b/LibraryCPP/list.cpp index 7af1761081..cf1e65fcf6 100644 --- a/LibraryCPP/list.cpp +++ b/LibraryCPP/list.cpp @@ -51,7 +51,7 @@ Data list_item_data(const ListItem *item) ListItem *list_item_next(ListItem *item) { - if(item != nullptr && item->next != nullptr) + if(item != nullptr) return item->next; return nullptr; } @@ -70,7 +70,10 @@ ListItem* list_insert(List* list, Data data) newEl->prev = nullptr; if (list->node != nullptr) + { newEl->next = list->node; + list->node->prev = newEl; + } else newEl->next = nullptr; @@ -119,6 +122,8 @@ ListItem *list_erase_next(List *list, ListItem *item) { item->next->next->prev = item; ListItem* temp = item->next->next; + if (temp != nullptr) + temp->prev = item; delete item->next; item->next = temp; return temp; From 0e78e129f514b563b5a7bec1822c0d41d77d4140 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 25 Sep 2024 16:30:55 +0300 Subject: [PATCH 57/73] Update stack.h --- LibraryCPP/stack.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LibraryCPP/stack.h b/LibraryCPP/stack.h index fedc0ad151..7c5dd97af2 100644 --- a/LibraryCPP/stack.h +++ b/LibraryCPP/stack.h @@ -1,6 +1,6 @@ #ifndef STACK_H #define STACK_H -#include "list.h" + // Stack // Stores integer values inside typedef int Data; From 39cead913301606b2c7613ef7698f8aa810c45be Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 25 Sep 2024 16:39:31 +0300 Subject: [PATCH 58/73] Update lab2.cpp --- Lab2CPP/lab2.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Lab2CPP/lab2.cpp b/Lab2CPP/lab2.cpp index 54cec2478a..f37e2f9953 100644 --- a/Lab2CPP/lab2.cpp +++ b/Lab2CPP/lab2.cpp @@ -1,6 +1,7 @@ #include #include #include +#include "list.h" #include "stack.h" unsigned int priority(const char symbol) From 0264738b971e17e99da93464c8dd3a38f8542805 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 25 Sep 2024 16:40:44 +0300 Subject: [PATCH 59/73] Update lab2.cpp --- Lab2CPP/lab2.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Lab2CPP/lab2.cpp b/Lab2CPP/lab2.cpp index f37e2f9953..54cec2478a 100644 --- a/Lab2CPP/lab2.cpp +++ b/Lab2CPP/lab2.cpp @@ -1,7 +1,6 @@ #include #include #include -#include "list.h" #include "stack.h" unsigned int priority(const char symbol) From 969b0b1e27adbc3b412e58ddf4bbc9767fcace02 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Wed, 25 Sep 2024 16:41:03 +0300 Subject: [PATCH 60/73] Update stack.cpp --- LibraryCPP/stack.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/LibraryCPP/stack.cpp b/LibraryCPP/stack.cpp index a0fc65b73b..5101c783ef 100644 --- a/LibraryCPP/stack.cpp +++ b/LibraryCPP/stack.cpp @@ -1,4 +1,5 @@ #include "stack.h" +#include "list.h" struct Stack { From 0a10a0f1a9d7d2c40a11bd1df2f278bd837ab976 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Thu, 26 Sep 2024 10:51:11 +0300 Subject: [PATCH 61/73] Update list.cpp --- LibraryCPP/list.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/LibraryCPP/list.cpp b/LibraryCPP/list.cpp index cf1e65fcf6..7f3e72eca5 100644 --- a/LibraryCPP/list.cpp +++ b/LibraryCPP/list.cpp @@ -91,7 +91,10 @@ ListItem *list_insert_after(List *list, ListItem *item, Data data) newEl->prev = item; if(item->next != nullptr) + { newEl->next = item->next; + item->next->prev = newEl; + } item->next = newEl; @@ -120,7 +123,8 @@ ListItem *list_erase_next(List *list, ListItem *item) { if (list != nullptr && item != nullptr && item->next != nullptr) { - item->next->next->prev = item; + if(item->next->next != nullptr) + item->next->next->prev = item; ListItem* temp = item->next->next; if (temp != nullptr) temp->prev = item; From f52b3cf1fbaf268ca4dbd19a3b57440ebf2cae17 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Thu, 26 Sep 2024 10:55:01 +0300 Subject: [PATCH 62/73] Update array.cpp --- LibraryCPP/array.cpp | 57 +++++++------------------------------------- 1 file changed, 9 insertions(+), 48 deletions(-) diff --git a/LibraryCPP/array.cpp b/LibraryCPP/array.cpp index fc0377198f..c773e5f167 100644 --- a/LibraryCPP/array.cpp +++ b/LibraryCPP/array.cpp @@ -2,72 +2,33 @@ struct Array { - Data* array; - size_t size; }; // create array -Array* array_create(size_t size) +Array *array_create(size_t size) { - if (size != 0) - { - Array* array = new Array; - array->size = size; - array->array = new Data[size]; - return array; - } - else - return nullptr; + return new Array; } // delete array, free memory -void array_delete(Array* arr) +void array_delete(Array *arr) { - if (arr->array != nullptr) - { - delete[] arr->array; - delete arr; - } + delete arr; } // returns specified array element -Data array_get(const Array* arr, size_t index) +Data array_get(const Array *arr, size_t index) { - if (index < arr->size) - return arr->array[index]; - else - return 0; + return (Data)0; } // sets the specified array element to the value -void array_set(Array* arr, size_t index, Data value) +void array_set(Array *arr, size_t index, Data value) { - if (index < arr->size) - { - arr->array[index] = value; - } } // returns array size -size_t array_size(const Array* arr) +size_t array_size(const Array *arr) { - if (arr->array != nullptr) - return arr->size; - return 0; -} - -// fill array from file -Array* fill_array(std::ifstream &in) -{ - size_t size; - Data value; - in >> size; - Array* array = array_create(size); - for (size_t i = 0; i < size; i++) - { - in >> value; - array_set(array, i, value); - } - - return array; + return 0; } From a77c95e1afdcdec65d18f4b94040278642d9aca3 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Fri, 27 Sep 2024 10:32:58 +0300 Subject: [PATCH 63/73] Update list.cpp --- LibraryCPP/list.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/LibraryCPP/list.cpp b/LibraryCPP/list.cpp index 7f3e72eca5..d7a5b0a1d3 100644 --- a/LibraryCPP/list.cpp +++ b/LibraryCPP/list.cpp @@ -82,25 +82,22 @@ ListItem* list_insert(List* list, Data data) return newEl; } -ListItem *list_insert_after(List *list, ListItem *item, Data data) +ListItem* list_insert_after(List* list, ListItem* item, Data data) { - if (list != nullptr && item != nullptr) + if (list != nullptr && item != nulltpr) { ListItem* newEl = new ListItem; - newEl->value = data; - newEl->prev = item; - if(item->next != nullptr) - { - newEl->next = item->next; - item->next->prev = newEl; - } + newEl->prev = item; + newEl ->next = item->next; + newEl->value = data; + if (item->next != nullptr) + item->next->previous = newEl; item->next = newEl; return newEl; } - return nullptr; } From 5bf832ee0cd6e16f4a1453178ecea0562432c25b Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Fri, 27 Sep 2024 10:34:16 +0300 Subject: [PATCH 64/73] Update list.cpp --- LibraryCPP/list.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LibraryCPP/list.cpp b/LibraryCPP/list.cpp index d7a5b0a1d3..a441e929e1 100644 --- a/LibraryCPP/list.cpp +++ b/LibraryCPP/list.cpp @@ -84,7 +84,7 @@ ListItem* list_insert(List* list, Data data) ListItem* list_insert_after(List* list, ListItem* item, Data data) { - if (list != nullptr && item != nulltpr) + if (list != nullptr && item != nullptr) { ListItem* newEl = new ListItem; @@ -93,7 +93,7 @@ ListItem* list_insert_after(List* list, ListItem* item, Data data) newEl->value = data; if (item->next != nullptr) - item->next->previous = newEl; + item->next->prev = newEl; item->next = newEl; return newEl; From 0f6f2a232e9c83ef89ffd5cca579f4e5d4dd64af Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Fri, 27 Sep 2024 10:37:58 +0300 Subject: [PATCH 65/73] Update lab2.cpp --- Lab2CPP/lab2.cpp | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/Lab2CPP/lab2.cpp b/Lab2CPP/lab2.cpp index 54cec2478a..db60dc116b 100644 --- a/Lab2CPP/lab2.cpp +++ b/Lab2CPP/lab2.cpp @@ -7,11 +7,11 @@ unsigned int priority(const char symbol) { if (symbol == '*' || symbol == '/') return 3; - if (symbol == '+' || symbol == '-') + if (symbol == '+' || symbol == '-') return 2; - if (symbol == '(') + if (symbol == '(') return 1; - + return 0; } @@ -96,7 +96,7 @@ Data solve(std::string data) } } - Data res = stack_get(stack); + Data res = stack_get(stack); stack_delete(stack); return res; } @@ -111,15 +111,8 @@ std::string calculate(std::string expr) int main() { - std::ifstream in("input.txt"); - - std::string temp = ""; - in >> temp; - std::cout << temp << " = " << calculate(temp); - - in >> temp; - std::cout << temp << " = " << calculate(temp); - - in.close(); - return 0; + std::string input = ""; + std::cin >> input; + std::cout << calculate(input); + return 0; } From 3acf5d9fd09b14159fc7ca9a5d1fd5908891886e Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Fri, 27 Sep 2024 10:38:51 +0300 Subject: [PATCH 66/73] Update CMakeLists.txt --- Lab2CPP/CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Lab2CPP/CMakeLists.txt b/Lab2CPP/CMakeLists.txt index ec593b4476..ecb0eaf722 100644 --- a/Lab2CPP/CMakeLists.txt +++ b/Lab2CPP/CMakeLists.txt @@ -2,4 +2,8 @@ add_executable(Lab2CPP lab2.cpp) target_include_directories(Lab2CPP PUBLIC ../LibraryCPP) target_link_libraries(Lab2CPP LibraryCPP) -add_test(NAME TestLab2CPP COMMAND Lab2CPP ${CMAKE_CURRENT_SOURCE_DIR}/input.txt) +add_test(NAME Test1 COMMAND Lab2CPP "1+2*3") +add_test(NAME Test2 COMMAND Lab2CPP "(1+2)*3") + +set_tests_properties(Test1 PROPERTIES PASS_REGULAR_EXPRESSION "7") +set_tests_properties(Test2 PROPERTIES PASS_REGULAR_EXPRESSION "9") From 8a43462dd5d058f7ab59824c78de2be2393bbeaa Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Fri, 27 Sep 2024 10:39:10 +0300 Subject: [PATCH 67/73] Delete Lab2CPP/input.txt --- Lab2CPP/input.txt | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 Lab2CPP/input.txt diff --git a/Lab2CPP/input.txt b/Lab2CPP/input.txt deleted file mode 100644 index 23cd4180d8..0000000000 --- a/Lab2CPP/input.txt +++ /dev/null @@ -1,2 +0,0 @@ -(1+2)*3 -1+2*3 From 2f2fea79ecc36a55373b33b9da09b46a582440ea Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Fri, 27 Sep 2024 15:32:32 +0300 Subject: [PATCH 68/73] Update lab2.cpp --- Lab2CPP/lab2.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Lab2CPP/lab2.cpp b/Lab2CPP/lab2.cpp index db60dc116b..93ccc1376d 100644 --- a/Lab2CPP/lab2.cpp +++ b/Lab2CPP/lab2.cpp @@ -1,7 +1,8 @@ #include #include #include -#include "stack.h" +#include "../LibraryCPP/list.h" +#include "../LibraryCPP/stack.h" unsigned int priority(const char symbol) { @@ -111,8 +112,8 @@ std::string calculate(std::string expr) int main() { - std::string input = ""; - std::cin >> input; - std::cout << calculate(input); + std::string data = ""; + std::cin >> data; + std::cout << calculate(data); return 0; } From 6dacaf4ff27168d2f48ec82bdd4a93fdf5175eb7 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Fri, 27 Sep 2024 15:34:00 +0300 Subject: [PATCH 69/73] Update CMakeLists.txt --- Lab2CPP/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lab2CPP/CMakeLists.txt b/Lab2CPP/CMakeLists.txt index ecb0eaf722..4ba5ebbdef 100644 --- a/Lab2CPP/CMakeLists.txt +++ b/Lab2CPP/CMakeLists.txt @@ -2,8 +2,8 @@ add_executable(Lab2CPP lab2.cpp) target_include_directories(Lab2CPP PUBLIC ../LibraryCPP) target_link_libraries(Lab2CPP LibraryCPP) -add_test(NAME Test1 COMMAND Lab2CPP "1+2*3") -add_test(NAME Test2 COMMAND Lab2CPP "(1+2)*3") +add_test(NAME Test1 COMMAND Lab2CPP 1+2*3) +add_test(NAME Test2 COMMAND Lab2CPP (1+2)*3) -set_tests_properties(Test1 PROPERTIES PASS_REGULAR_EXPRESSION "7") -set_tests_properties(Test2 PROPERTIES PASS_REGULAR_EXPRESSION "9") +set_tests_properties(Test1 PROPERTIES PASS_REGULAR_EXPRESSION 7) +set_tests_properties(Test2 PROPERTIES PASS_REGULAR_EXPRESSION 9) From c18867c2ce64558baf067d29cedc135dec8b04ee Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Fri, 27 Sep 2024 15:38:05 +0300 Subject: [PATCH 70/73] Update CMakeLists.txt --- Lab2CPP/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lab2CPP/CMakeLists.txt b/Lab2CPP/CMakeLists.txt index 4ba5ebbdef..ecb0eaf722 100644 --- a/Lab2CPP/CMakeLists.txt +++ b/Lab2CPP/CMakeLists.txt @@ -2,8 +2,8 @@ add_executable(Lab2CPP lab2.cpp) target_include_directories(Lab2CPP PUBLIC ../LibraryCPP) target_link_libraries(Lab2CPP LibraryCPP) -add_test(NAME Test1 COMMAND Lab2CPP 1+2*3) -add_test(NAME Test2 COMMAND Lab2CPP (1+2)*3) +add_test(NAME Test1 COMMAND Lab2CPP "1+2*3") +add_test(NAME Test2 COMMAND Lab2CPP "(1+2)*3") -set_tests_properties(Test1 PROPERTIES PASS_REGULAR_EXPRESSION 7) -set_tests_properties(Test2 PROPERTIES PASS_REGULAR_EXPRESSION 9) +set_tests_properties(Test1 PROPERTIES PASS_REGULAR_EXPRESSION "7") +set_tests_properties(Test2 PROPERTIES PASS_REGULAR_EXPRESSION "9") From dbcf9c8628aafb67ccb7e91c2719dea00f5b7774 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Fri, 27 Sep 2024 15:41:39 +0300 Subject: [PATCH 71/73] Update lab2.cpp --- Lab2CPP/lab2.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Lab2CPP/lab2.cpp b/Lab2CPP/lab2.cpp index 93ccc1376d..b7be72b4f2 100644 --- a/Lab2CPP/lab2.cpp +++ b/Lab2CPP/lab2.cpp @@ -1,8 +1,8 @@ #include #include #include -#include "../LibraryCPP/list.h" -#include "../LibraryCPP/stack.h" +#include "list.h" +#include "stack.h" unsigned int priority(const char symbol) { @@ -110,10 +110,15 @@ std::string calculate(std::string expr) return expr; } -int main() +int main(int argc, char** argv) { std::string data = ""; - std::cin >> data; + char* ch = argv[1]; + while (*ch != '\0') + { + data += *(ch); + ch++; + } std::cout << calculate(data); return 0; } From 2a773a7494e4ffa90c29822fb85bd9a643c5775b Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Mon, 30 Sep 2024 08:42:25 +0300 Subject: [PATCH 72/73] Update list.cpp --- LibraryCPP/list.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/LibraryCPP/list.cpp b/LibraryCPP/list.cpp index a441e929e1..dd3f37c0c8 100644 --- a/LibraryCPP/list.cpp +++ b/LibraryCPP/list.cpp @@ -123,8 +123,7 @@ ListItem *list_erase_next(List *list, ListItem *item) if(item->next->next != nullptr) item->next->next->prev = item; ListItem* temp = item->next->next; - if (temp != nullptr) - temp->prev = item; + temp->prev = item; delete item->next; item->next = temp; return temp; From 831dfe23eee835fbec51a7e1fc70b31b8f2afac5 Mon Sep 17 00:00:00 2001 From: tolstosup <154780185+tolstosup@users.noreply.github.com> Date: Tue, 1 Oct 2024 08:40:20 +0300 Subject: [PATCH 73/73] Update list.cpp --- LibraryCPP/list.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/LibraryCPP/list.cpp b/LibraryCPP/list.cpp index dd3f37c0c8..a36021b4cd 100644 --- a/LibraryCPP/list.cpp +++ b/LibraryCPP/list.cpp @@ -123,7 +123,6 @@ ListItem *list_erase_next(List *list, ListItem *item) if(item->next->next != nullptr) item->next->next->prev = item; ListItem* temp = item->next->next; - temp->prev = item; delete item->next; item->next = temp; return temp;