C# BFS
BFS, output by each level during traverse, O(R*C).\n\n\npublic int[][] AllCellsDistOrder(int R, int C, int r0, int c0) {\n        List<int[]> res=new List<int[]
BFS, output by each level during traverse, O(R*C).\n\n```    \npublic int[][] AllCellsDistOrder(int R, int C, int r0, int c0) {\n        List<int[]> res=new List<int[]>();\n        Queue<int[]> q=new Queue<int[]>();\n        int[,] visited=new int[R,C];\n        \n        q.Enqueue(new int[]{r0,c0});\n        visited[r0,c0]=1;\n        while(q.Count>0){\n            int[] current=q.Dequeue();\n            res.Add(current);\n            enqueue(R,C,current[0]-1,current[1], visited,q);\n            enqueue(R,C,current[0]+1,current[1],visited,q);\n            enqueue(R,C,current[0],current[1]-1,visited,q);\n            enqueue(R,C,current[0],current[1]+1,visited,q);                \n        }\n        return res.ToArray();\n    }\n    \n    public void enqueue(int R, int C, int i,int j, int[,] visited, Queue<int[]> q){\n        if(i>=0&&i<R&&j>=0&&j<C&&visited[i,j]==0){\n            q.Enqueue(new int[]{i,j});\n            visited[i,j]=1;\n        }\n    }\n```
['Breadth-First Search']