diff options
Autocommit at 02.05.2022 @ 08:10
2 files changed, 20 insertions, 2 deletions
| -rw-r--r-- | src/List/List.cpp | 18 | ||||
| -rw-r--r-- | src/List/List.h | 4 |
diff --git a/src/List/List.cpp b/src/List/List.cpp index bdb9b4a..a0d0849 100644 --- a/src/List/List.cpp +++ b/src/List/List.cpp @@ -62,6 +62,24 @@ const T& List<T>::operator[](unsigned index) const { } template <class T> +std::istream& List<T>::read(std::istream& istr) { + istr.read((char*)&length, sizeof(length)); + istr.read((char*)&count, sizeof(count)); + delete[] elements; + elements = new T[length]; + + for (int i = 0; i < count; i++) + istr >> elements[i]; + + return istr; +} + +template <class T> +std::ostream& List<T>::write(std::ostream& ostr) const { + return ostr; +} + +template <class T> unsigned List<T>::get_length() const { return length; } diff --git a/src/List/List.h b/src/List/List.h index 0e7722c..377cbf0 100644 --- a/src/List/List.h +++ b/src/List/List.h @@ -21,8 +21,8 @@ public: T& operator[](unsigned index); const T& operator[](unsigned index) const; - std::istream read(std::istream& istr); - std::ostream write(std::istream& ostr); + std::istream& read(std::istream& istr); + std::ostream& write(std::ostream& ostr) const; unsigned get_length() const; unsigned get_count() const; |
