Simple BFS Traversal (C++)
Intuition\n  BFS Traversal will help to traverse every cells, and also store the distance along with it.\n\n# Approach\n - Push the center coordinates in queue 
# Intuition\n  BFS Traversal will help to traverse every cells, and also store the distance along with it.\n\n# Approach\n - Push the center coordinates in queue with curr dis = 0;\n - Created a visited array , so that you dont come back to same element again.\n - While queue is not empty\n    i) Pop the front and w.r.t to that element check in all 4 directions if cell is not visited , push them in the queue and increase the distance\n  ii) Mark cells visited along with that\n\n\n\n# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> allCellsDistOrder(int r, int c, int a, int b) {\n        int visited[r][c];\n        for(int i=0;i<r;i++)\n        {\n            for(int j=0;j<c;j++)\n               visited[i][j]=0;\n        }\n        queue<pair<pair<int,int>, int> >q;\n        q.push({{a, b},0 });\n        visited[a][b]=1;\n        int xdir[4]={1,-1, 0, 0};\n        int ydir[4]={0,0, 1,-1};\n        vector<pair<int, pair<int,int> > >res;\n        vector<vector<int>>coord;\n        while(!q.empty())\n        {\n            auto p = q.front();\n            q.pop();\n            int x = p.first.first;\n            int y = p.first.second;\n            int dis = p.second;\n            res.push_back({dis,{x, y}});\n            for(int k =0;k<=3;k++)\n            {\n                int xnew = x+xdir[k];\n                int ynew = y+ydir[k];\n                if(xnew>=0 && xnew<r && ynew>=0 &&ynew<c && visited[xnew][ynew]==0)\n                {\n                    q.push({{xnew, ynew}, dis+1});\n                    visited[xnew][ynew]=1;\n\n                }\n            }\n        }\n        sort(res.begin(), res.end());\n        for(int i=0;i<res.size();i++)\n        {\n            vector<int>temp(2,0);\n            temp[0] = res[i].second.first;\n            temp[1] = res[i].second.second;\n            coord.push_back(temp);\n        }\n        return coord;\n    }\n};\n```
['Breadth-First Search', 'C++']