From e5c06fbc864205a9736f07f9237ace80617ca471 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 16 Mar 2026 22:41:31 +0200 Subject: feat(Week04): Add solutions --- Week04/Exercise02/IntArray.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Week04/Exercise02/IntArray.h (limited to 'Week04/Exercise02/IntArray.h') diff --git a/Week04/Exercise02/IntArray.h b/Week04/Exercise02/IntArray.h new file mode 100644 index 0000000..0ed99c9 --- /dev/null +++ b/Week04/Exercise02/IntArray.h @@ -0,0 +1,44 @@ +#ifndef _INTARRAY +#define _INTARRAY + +class IntArray { + int* elems; + unsigned capacity; + + /* Как трябва да изглежда голяма четворка: */ + + void free() { + delete[] elems; + } + void copyFrom(const IntArray& other) { + capacity = other.capacity; + + elems = new int[capacity]; + for (unsigned i = 0; i < capacity; ++i) + elems[i] = other.elems[i]; + } +public: + IntArray() { + elems = nullptr; + capacity = 0; + } + ~IntArray() { + free(); + } + IntArray(const IntArray& other) { + copyFrom(other); + } + IntArray& operator=(const IntArray& other) { + if (this != &other) { + free(); + copyFrom(other); + } + return *this; + } + + int At(unsigned index); + void Resize(unsigned capacity); + void Concat(const IntArray& endElements); +}; + +#endif /* _INTARRAY */ -- cgit v1.3.1-23-gd82d