<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # 通過遵循單元格值來查找二維數組是否被完全遍歷 > 原文: [https://www.geeksforgeeks.org/find-2-d-array-completely-traversed-not-following-cell-values/](https://www.geeksforgeeks.org/find-2-d-array-completely-traversed-not-following-cell-values/) 您將獲得一個二維數組。 我們必須遵循單元格位置遍歷給定數組的每個單元格,然后返回 true 或 false。 每個單元格的值由(x,y)給出,其中(x,y)也顯示接下來的下一個單元格位置。 例如。 (0,0)顯示起始單元格。 “空”表示遍歷每個單元格后的最終目的地。 ![](https://img.kancloud.cn/da/57/da57ff3e35c3e70f52822595a1fc2a40_601x315.png) **示例**: ``` Input : { 0, 1 1, 2 1, 1 0, 2 2, 0 2, 1 0, 0 1, 0 null } Output : false Input : { 0, 1 2, 0 null 1, 0 2, 1 1, 1 } Output : true ``` 如果訪問一個單元格,則采用一個訪問數組,然后在訪問數組中將其值設為 true,以便下次再次訪問它時可以捕獲網格中的循環。 而且,如果我們在完成循環之前發現 null,則意味著我們沒有遍歷給定數組的所有單元格。 ## Java ```java /* Java program to Find a 2-D array is completely traversed or not by following the cell values */ import java.io.*; class Cell { ????int x; ????int y; ????// Cell class constructor ????Cell(int x, int y) ????{ ????????this.x = x; ????????this.y = y; ????} } public class MoveCellPerCellValue { ????// function which tells all cells are visited or not ????public boolean isAllCellTraversed(Cell grid[][]) ????{ ????????boolean[][] visited =? ??????????????new boolean[grid.length][grid[0].length]; ????????int total = grid.length * grid[0].length; ????????// starting cell values ????????int startx = grid[0][0].x; ????????int starty = grid[0][0].y; ????????for (int i = 0; i < total - 2; i++) { ????????????// if we get null before the end of loop? ????????????// then returns false. Because it means we? ????????????// didn't traverse all the cells ????????????if (grid[startx][starty] == null)? ????????????????return false; ????????????// If found cycle then return false ????????????if (visited[startx][starty] == true)? ????????????????return false; ????????????visited[startx][starty] = true; ????????????int x = grid[startx][starty].x; ????????????int y = grid[startx][starty].y; ????????????// Update startx and starty values to next ????????????// cell values ????????????startx = x; ????????????starty = y; ????????} ????????// finally if we reach our goal then returns true ????????if (grid[startx][starty] == null)? ????????????return true; ????????return false; ????} ????/* Driver program to test above function */ ????public static void main(String args[]) ????{ ????????Cell cell[][] = new Cell[3][2]; ????????cell[0][0] = new Cell(0, 1); ????????cell[0][1] = new Cell(2, 0); ????????cell[1][0] = null; ????????cell[1][1] = new Cell(1, 0); ????????cell[2][0] = new Cell(2, 1); ????????cell[2][1] = new Cell(1, 1); ????????MoveCellPerCellValue mcp = new MoveCellPerCellValue(); ????????System.out.println(mcp.isAllCellTraversed(cell)); ????} } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看