//==================================================================== // // Program Name: Random Routing // Assignment: 4 // Date: March 22, 2009 // // Programmer: Nomed Nocaed // Course: CSC 221 A Professor: Nirre Pluf // // Program Description: // Simulate random routing algorithm recursively, truly awesome // anyone who says otherwise gets a punch in the face //==================================================================== #include #include"network.h" using namespace std; #define NORM "\33[0m" int main(int argc, char* argv[]) { unsigned int seed = 10; // in order to generate the same network char** net; // network array int maxRow = 5; // number of rows int maxCol = 5; // number of columns int row = 0; // current row int col = 0; // current column bool pathFound = false; // to see if a path exists // convert command line arugments if provided if(argc >= 2) maxRow = atoi(argv[1]); if(argc >= 3) maxCol = atoi(argv[2]); if(argc >= 4) seed = atoi(argv[3]); // allocate the matrix net = new (nothrow) char*[maxRow]; if(!net) { cerr << argv[0] << " could not allocate memory \n"; return 1; } for(int i = 0; i < maxRow; i++) { net[i] = new (nothrow) char[maxCol]; if(!net[i]) { cerr << argv[0] << " could not allocate memory \n"; return 2; } } genNetwork(net, maxRow, maxCol, seed); printNetwork(net, maxRow, maxCol); determineRoute(net, maxRow, maxCol, row, col, pathFound); if (!pathFound) { cout << NORM << "No Valid Route! \n"; return 0; } printNetwork(net, maxRow, maxCol); // delete martix for(int i = 0; i < maxRow; i++) if(net && net[i]) delete [] net[i]; if(net) delete [] net; return 0; }