1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
// return the number of times the sentence starts from startRow/startColumn
int countReadsRecursive(char grid [30] [30] [101],
int gridRows, int gridColumns,
int startRow, int startColumn,
char *sentence)
{
// The following bounds checks are needed for the recursive calls
// if startRow<0 || startRow > gridRows) return 0; // startRow out of bounds
// if startColumn<= 0 || startColumn > gridColumns) return 0; // startColumn out of
bounds
// See if grid[startRow][startColumn] contains the first word of the sentence
// if it doesn't then return 0.
// If it does then
// set char *newSentence to point to the next word in the sentence.
// return countReadsRecursive(grid, gridRows, gridColumns, startRow-1, startColumn, newSentence) +
countReadsRecursive(grid, gridRows, gridColumns, startRow, startColumn-1, newSentence) +
countReadsRecursive(grid, gridRows, gridColumns, startRow, startColumn+1, newSentence) +
countReadsRecursive(grid, gridRows, gridColumns, startRow+1, startColumn, newSentence);
}
|