From 0bd2ab4d1f9e8fdbf55ed11d61fe2e75720a334a Mon Sep 17 00:00:00 2001 From: justanothercatgirl Date: Thu, 17 Apr 2025 12:48:23 +0300 Subject: finished 206, 207 --- libprakpp/include/prakmatrix.hpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'libprakpp/include/prakmatrix.hpp') diff --git a/libprakpp/include/prakmatrix.hpp b/libprakpp/include/prakmatrix.hpp index f1ccddc..2f87401 100644 --- a/libprakpp/include/prakmatrix.hpp +++ b/libprakpp/include/prakmatrix.hpp @@ -2,6 +2,7 @@ #include "prakcommon.hpp" +#include #include #include #include @@ -75,7 +76,7 @@ struct matrix : public std::vector { } /// multiply matrix by a scalar template - std::enable_if_t, struct matrix>::type + typename std::enable_if_t, struct matrix>::type operator*(const Arg other) const { struct matrix ret(rows, cols); for (size_t i = 0; i < this->size(); ++i) @@ -161,12 +162,27 @@ struct matrix : public std::vector { } return ret; } + + void add_row(size_t index, std::vector row_data) { + ++rows; + this->resize(rows * cols); + memmove(this->data() + cols * (index+1), this->data() + cols * index, (rows - index - 1) * cols * sizeof (T)); + for (size_t i = 0; i < cols; ++i) + this->operator[](index * cols + i) = row_data[i]; + } + void add_column(size_t index, std::vector column_data) { + this->reserve(rows * (cols + 1)); + for (size_t i = 0; i < rows; ++i) + this->insert(this->begin() + (cols + 1) * i + index, column_data[i]); + ++cols; + } std::ostream &print(std::ostream &out = std::cout, size_t width = 10) const { + std::cout.setf(std::ios::left); for (size_t row = 0; row < rows; ++row) { for (size_t col = 0; col < cols; ++col) - out << "|" << std::setw(width) << SUBSCR_OPRTR(row, col); - std::cout << "|\n"; + out /*<< "|"*/ << std::setw(width) << SUBSCR_OPRTR(row, col); + std::cout << "\n"; } return out; } -- cgit v1.2.3-70-g09d2