#include #include #include using namespace std; template class matrix { protected: int rows, cols; T * data; public: matrix(int r, int c) { rows = r; cols = c; data = new T[r * c]; } ~matrix() { delete [] data; } int numrows() { return rows; } int numcols() { return cols; } T & at(int r, int c) { assert(r >= 0 && r < rows); assert(c >= 0 && c < cols); return data[r * cols + c]; } }; bool explore(matrix & map, int here, int dest) { if (here == dest) return true; int N = map.numrows(); for (int via = 0; via < N; via += 1) int main(int argc, char * argv[]) { assert(argc == 2); ifstream fin(argv[1]); if (fin.fail()) { cerr << "Can't read " << argv[1] << "\n"; exit(1); } int N; fin >> N; matrix map(N, N); for (int r = 0; r < N; r += 1) for (int c = 0; c < N; c += 1) fin >> map.at(r, c); fin.close(); for (int r = 0; r < N; r += 1) { for (int c = 0; c < N; c += 1) cout << map.at(r, c) << " "; cout << "\n"; } int from, to; cout << "start point and destination? "; cin >> from >> to; bool success = explore(map, from, to); cout << (success ? "Found it\n" : "Failed\n"); }