satishl
BAN USERLegal! The below code works perfectly fine.
int& means return by reference, basically returning the reference to address of a, which is then populated with the value on the right side of =.
int a = 10;
int& function()
{
return a;
}
int _tmain(int argc, _TCHAR* argv[])
{
int x = 5;
function() = x;
return 0;
}
int FindAdjacentOns(int** matrix, int rows, int cols)
{
int groupCount = 0;
for (int i=0; i< rows ; i++)
{
for(int j=0; j< cols ; j++)
{
if(matrix[i][j] == 1)
{
groupCount ++;
CheckAdjacent( matrix, i, j)
}
}
}
return groupCount;
}
void CheckAdjacent(int** matrix, int i, int j, int rows, int cols)
{
if (matrix != null && matrix[i][j] == 0)
{
return;
}
matrix[i][j] = 0;
if (i > 0)
{
CheckAdjacent(matrix, i - 1, j, rows, cols);
}
if (j > 0)
{
CheckAdjacent(matrix, i - 1, j, rows, cols);
}
if (i < rows - 1)
{
CheckAdjacent(matrix, i + 1, j, rows, cols);
}
if (j < cols - 1)
{
CheckAdjacent(matrix, i, j + 1, rows, cols);
}
}
You also have a problem with this input.
- satishl November 30, 2011input: {1,2,3,4,5} , sum = 10.
this function will return 5,5 as the answer, where as the right answer is none.