#pragma once #include #include using namespace std; template class MultiArray { public: T* _data; vector _dims; MultiArray(){ _data = new T[0]; _dims = vector(N, 0); } ~MultiArray(){ delete[] _data; } MultiArray(const MultiArray& other){ vector dims = other._dims; vector data; int len = 1; for(int i=0;i(N, 0); _dims[0] = data.size(); for(int i=0;i &dims, const vector &data = vector()){ if(data.empty()){ _dims = dims; int len = 1; for(int i=0;i(N, 0); _dims[0] = data.size(); for(int i=0;i& idx) const { int _idx = 0; int temp = 1; for(int i=0;i get_idx_vec(const int& idx) const { vector _idx(N, 0); int rem = idx; for(int i=0;i &idx, const T &val){ int _idx = get_idx(idx); _data[_idx] = val; } T& get(const vector &idx){ int _idx = get_idx(idx); return _data[_idx]; } vector& get_dims(){ return _dims; } template bool operator ==(const MultiArray &other) const{ if(M!=N){ return false; } for(int i=0;i bool operator !=(const MultiArray &other) const{ if(M!=N){ return true; } for(int i=0;i &other){ if(this!=&other){ _dims = other._dims; delete[] _data; int len = 1; for(int i=0;i_data[_idx]; } Iterator& operator++(){ ++_idx; return *this; } Iterator operator++(int){ Iterator new_ite(_arr, _idx); ++_idx; return new_ite; } bool operator!=(const Iterator& other) const{ return (_idx!=other._idx) || (_arr!=other._arr); } bool operator==(const Iterator& other) const{ return (_idx==other._idx) && (_arr==other._arr); } Iterator& operator=(const Iterator& other){ _arr = other. _arr; _idx = other._idx; return *this; } }; Iterator begin() const{ return Iterator(this, 0); } Iterator end() const{ int len = 1; for(int i=0;i &dims2); void resize(const vector &dims2); }; template std::ostream& operator <<(std::ostream& out, const MultiArray& a){ int len = 1; for(int i=0;i _index = a.get_idx_vec(i); for(int j=0;j