/ / Looking for path from location (1, 1) to export (M, M) int ** maze, m; stack * path; bool findpath () {path = new stack (m * m- 1); position offset [4]; Offset [0] .Row = 0; Offset [0] .col = 1; // Right Offset [1] .ROW = 1; Offset [1] .col = 0; // Down Offset [2] .Row = 0; Offset [2] .col = -1; // Left offset [3] .row = -1; offset [3] .col = 0; // Up // around the labyrinth Increase a trap for (int i = 0; i add (here); here.row = r; here.col = c; // Set obstacle to prevent re-access maze [ r] [C] = 1; option = 0;} else {// No location available, backtracking IF (path-> iSempty ()) Return False; POSITION NEXT; PATH-> Delete (next); if (Next); ROW == here.row) Option = 2 next.col-here.col; else option = 3 next.row-here.row; here = next;}} return true;}} Return True;
Ref: << Data Structure, Algorithm & Applications >> P180 ~ 186