Implementation of DIJKSTRA ALGORITHM (in C/C++) : Problem Statement : A robot has to traverse from one end of an mXn arena to the other . The arena is in the form of a rectangular grid . In the co-ordinate system we will use , the top left cell is (0,0) (i.e. the X cell shown). and the bottom right cell is (m-1,n-1) . (i.e. the Y cell shown ) . Some of these grids have obstacles as shown with 'B' and the robot cannot go through these paths . Your task is to find a path from the X cell to the Y cell . Input format: m n Output : <-1 -1> If no path exists : -1 -1 Example arena : X------- -B----B- B------- --B----- ----BB-- ----B--- -----B-B -----B-B B------Y Input : 8 8 10 1 1 6 1 0 2 2 3 4 4 5 4 4 5 5 6 7 6 0 7 Sample Output: 0 0 1 0 2 0 2 1 2 2 3 2 4 2 5 2 6 2 6 3 6 4 6 5 6 6 6 7 7 7 -1 -1 PROGRAM: ( TRIED AND TESTED IN TURBO C++ ) --------------------------------------------------- # include # include struct Matrix { short int **array; int row;int col; }; struct Vertex { int num ; int currDist ; }; typedef struct Matrix matrix; typedef struct Vertex vertex; void getGrid(matrix &m1); void getShortestPath(); /* Dijkstra Algorithm */ void printSolution(int p[],int index); matrix m; int main() { getGrid(m); getShortestPath(); printf("\n-1 -1\n\n"); free(m.array); return 0; } void getGrid(matrix &m) {int ctr1,ctr2,blockedSquares,x,y; scanf("%d%d%d",&m.row,&m.col,&blockedSquares); m.array=(short int **)malloc(m.row*sizeof(short int *)) ; for(ctr1=0;ctr1minVertex.currDist+1) { toBeChecked[ctr1].currDist=minVertex.currDist+1; if(toBeChecked[ctr1].num!=0) predecessor[toBeChecked[ctr1].num]=minVertex.num; }; } } printSolution(predecessor,m.row*m.col-1); } void printSolution(int p[],int index) { if(index==0) { printf("\n0 0"); return ; }; if(p[index]==31000) return; printSolution(p,p[index]); printf("\n%d %d",index/m.col,index%m.col); }