"How can I make it into 8x8 dimension." HELP ME KNIGHT'S TOUR.
Should I use Vector Void, Or Bool??? Help.
Last edited on
Keep it simple store your data in a simple struct or class (it's up to you). Then store an instance of this struct/class in a std::vector:
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
|
#include <iostream>
#include <vector>
using namespace std;
struct SData
{
SData() : val('*')
{
}
char val;
friend std::ostream& operator << (std::ostream& os, const SData& data)
{
os << data.val << '|';
return os;
}
};
class Matrix
{
public:
Matrix()
: rows(0)
, cols(0)
{
}
Matrix(const int _rows, const int _cols)
: rows(_rows)
, cols(_cols)
{
for (int r = 0; r < rows; ++r)
{
for (int c = 0; c < cols; ++c)
{
SData sd;
matrix.push_back(sd);
}
}
}
int MaxRow() { return rows; }
int MaxCol() { return cols; }
void CellValue(const int row, const int col, char value)
{
matrix[row-1 + col-1].val = value;
}
private:
const int rows;
const int cols;
vector<SData> matrix;
};
int main ()
{
Matrix m(8, 8); // results in 8x8 board aka matrix
return 0;
}
|
Last edited on
Topic archived. No new replies allowed.