Okay...I have this array see and its 5x5 and I'm doing something similiar to the game of life (but not really..its different) I need to check the neighbors for a certain element in the array, and determine whether to move that element or keep it in its spot. my problem is not with the middle element because it has its eight neighbors and that's fine, my problem lies in the corners, and the edges which have respectively 3, and 5 neighbors. I was wondering if anyone knew how to both, tell a spot is a corner or edge, and how to manipulate the neighbors without hard coding a specific function for corners, and edges..
Here is some code that tells you whether an element is an edge..
CODE
srand(time(NULL));
int rows, columns, i , j;
int **matrix;
cin >> rows >> columns;
matrix = new int* [rows];
for (i = 0; i< rows; i++)
matrix[i] = new int[columns];
//Fill the array with 0's
for(int row = 0; row < rows; row++)
for(int col = 0; col < columns; col++)
matrix[row][col] = rand() %2;
for (int a=0; a<rows; a++)
{
for (int b=0; b<columns; b++)
{
if(a ==0 || a== rows-1)
cout << "(" << a << "," << b << ") is an edge" << endl;
if(b ==0 || b== columns-1)
cout << "(" << a << "," << b << ") is an edge" << endl;
}
}
// Print the array
for (int pRow = 0; pRow < rows; pRow++)
{
for (int pCol = 0; pCol< columns; pCol++)
{
cout << matrix[pRow][pCol];
}
cout << endl;
}
for (i=0; i<rows; i++)
delete[] matrix[i];
delete [] matrix;
return 0;
}