Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Mat : public std::vector<double *>{
- public:
- std::vector<int> dlugosci;
- Mat(){};
- ~Mat(){
- }
- double* addRow(int size){
- push_back(new double[size]);
- dlugosci.push_back(size);
- return back();
- }
- void deleteRow(int r){
- if (r<0 || r>=size() ) throw -1;
- else{
- int licznik=0;
- vector<double *>::iterator it;
- for (it=begin(); it!=end(); ++it){
- if (licznik==r){
- delete[] at(r);
- erase(it);
- return;
- }
- licznik++;
- }
- }
- }
- double &operator()(int row, int col){
- if (row<0 || row>=size() || col<0 || col>=dlugosci[row]) throw -1;
- else return at(row)[col];
- }
- Mat operator+(Mat &other){
- Mat result;
- int rozmiar = max(dlugosci.size(),other.dlugosci.size());
- for (int i=0; i<rozmiar; ++i){
- int maxi = max(dlugosci[i],other.dlugosci[i]);
- result.addRow(maxi);
- for (int j=0; j<maxi; j++){
- if (j<dlugosci[i] && j<other.dlugosci[i]) result(i,j) = at(i)[j]+other.at(i)[j];
- else if (j>=dlugosci[i] && j<other.dlugosci[i]) result(i,j) = other.at(i)[j];
- else if (j<dlugosci[i] && j>=other.dlugosci[i]) result(i,j) = at(i)[j];
- }
- }
- return result;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement