// Assume a lava flow is entering (row,col) from an elevation of "inElevation". // If (row,col) has a greater elevation, the lava flow is stopped. // Otherwise, (row,col) gets scorched and lava may flow up, down, left, and right from this cell. // Every "scorched" cell gets set to an elevation of zero. void doLavaFlow(int **map, int numRows, int numCols, int row, int col, int inElevation) { // If this location is out of bounds, we've gone off edge, so stop if (!inBounds(numRows, numCols, row, col)) { return; } int thisElevation = map[row][col]; // There is lava entering (row,col) at the given elevation. // BUT if elevation of current cell is higher, this cell stops the lava if (thisElevation > inElevation) { return; // we stopped the lava! } // OR if this cell is already scorched, no need to handle this one again if (thisElevation == 0) { return; // already scorched } // Okay, this cell is scorched // mark with zero map[row][col] = 0; // Lava can flow from this point, at this elevation, to four surrounding areas. doLavaFlow(map, numRows, numCols, row-1, col , thisElevation); doLavaFlow(map, numRows, numCols, row+1, col , thisElevation); doLavaFlow(map, numRows, numCols, row , col-1, thisElevation); doLavaFlow(map, numRows, numCols, row , col+1, thisElevation); return; }