Class_Examples/src/HomeworkAnswers/Islands.java
public int noOfIslands(char[][] inputTable)
    {
        int flag = 0;
        int count=0;
        start:
        for (int r = 0; r< inputTable.length; r++)
        {
            for (int c = 0; c < inputTable[r].length; c++)
            {
                if (inputTable[r][c] == 'L')
                {
                    flag = dfs(inputTable, r ,c);
                    if(flag>0)
                        ++count;
                    break start;
                }
            }
        }
        return count;
    }
//To go through each element of the matrix and call the dfs function on the 1's
To go through each element of the matrix and call the dfs function on the 1's
To go through each element of the matrix and call the dfs function on the 1 ' s
public int noOfIslands(char[][] inputTable)
    {
        int flag = 0;
        int count=0;
        start:
        for (int r = 0; r< inputTable.length; r++)
        {
            for (int c = 0; c < inputTable[r].length; c++)
            {
                if (inputTable[r][c] == 'L')
                {
                    flag = dfs(inputTable, r ,c);
                    if(flag>0)
                        ++count;
                    break start;
                }
            }
        }
        return count;
    }
public int noOfIslands ( char [ ] [ ] inputTable ) { int flag = 0 ; int count = 0 ; start : for ( int r = 0 ; r < inputTable . length ; r ++ ) { for ( int c = 0 ; c < inputTable [ r ] . length ; c ++ ) { if ( inputTable [ r ] [ c ] == 'L' ) { flag = dfs ( inputTable , r , c ) ; if ( flag > 0 ) ++ count ; break start ; } } } return count ; }
To go through each element of the matrix and call the dfs function on the 1's
To go through each element of the matrix and call the dfs function on the 1 ' s