1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#ifndef MATRIX_H
#define MATRIX_H
#include "dlist.h"
#include "zlist.h"
const int MAXSIZE = 4;
template <class Instance_of_Type, class Mat> void RESIZE(Instance_of_Type instance, Mat & m, int newRows, int newCols)
{
int tr = m.myRows, tc = m.myCols;
m.myRows = newRows; m.myCols = newCols;
for (int x = 0; x < newRows; ++x)
for (int y = 0; y < newCols; ++y)
if (x >= tr || y >= tc)
m(x,y) = 0;
return;
}
template <class Mat> void RESIZE(dlist frikken, Mat & m, int newRows, int newCols)
{
int tr = m.myRows, tc = m.myCols;
m.myRows = newRows; m.myCols = newCols;
for (int i = 0; i < newRows; ++i)
for (int j = 0; j < newCols; ++j)
{
cout << "m(" << i << ", " << j << ").length = " << m(i, j).length << endl;
m(i, j).resize(newRows); cout << "after it is " << m(i, j).length << endl;
if (i >= tr || j >= tc)
m(i, j) = 0;
}
return;
}
template <class Mat> void RESIZE(zlist frikken, Mat & m, int newRows, int newCols)
{
int tr = m.myRows, tc = m.myCols;
m.myRows = newRows; m.myCols = newCols;
return;
for (int i = 0; i < newRows; ++i)
for (int j = 0; j < newCols; ++j)
{
//m(i, j).resize(newRows);
if (i >= tr || j >= tc)
m(i, j) = 0;
else m(i, j).resize(newRows);
}
return;
}
template <class itemType>
class matrix
{
public:
matrix( ); // default size 0 x 0
matrix( int rows, int cols ); // size rows x cols
matrix( int rows, int cols,
const itemType & fillValue ); // all entries == fillValue
matrix( const matrix & mat ); // copy constructor
~matrix( );
// assignment
const matrix & operator = ( const matrix & rhs );
//bool apmatrix & operator == ( const apmatrix & rhs );
bool operator == (const matrix & rhs) const;
bool operator != (const matrix & rhs) const;
int numrows( ) const; // number of rows
int numcols( ) const; // number of columns
const void displaymatrix();
void resize(int newRows, int newCols);
itemType & operator ( ) (int k, int y);
const itemType & operator ( ) (int k, int y) const;
int myRows; // # of rows (capacity)
int myCols; // # of cols (capacity)
const void clear();
private:
itemType myMatrix[MAXSIZE][MAXSIZE];
};
#include "matrix.cpp"
#endif
|