algorithm to code help


function FIND SHORTEST PATH(Grid world)
q<-new Queue;
s<-new Stack;

Initialise a Distance array of NumRows by NumCols to MAX.INT;


Distance[startR][startC]<-0;

Parent[startR][startC]<-(-2,-2);

Enqueue(startR, startC);

while q isn’t empty and we haven’t discovered the goal do
curr<-Dequeue(q);

tmp<-cell below curr;

if tmp is open and undiscovered then
Distance(tmp)<-Distance(curr) + 1;
Parent(tmp)<-curr;
Discovered(tmp)<-True;
Enqueue(tmp);

end if
tmp<-cell left of curr;

if tmp is open and undiscovered then
Distance(tmp)<-Distance(curr) + 1;
Parent(tmp)<-curr;
Discovered(tmp)<-True;
Enqueue(tmp);

end if
tmp<-cell above curr;

if tmp is open and undiscovered then
Distance(tmp)<-Distance(curr) + 1;
Parent(tmp)<-curr;
Discovered(tmp)<-True;
Enqueue(tmp);

end if
tmp<-cell right of curr;

if tmp is open and undiscovered then
Distance(tmp)<-Distance(curr) + 1;
Parent(tmp)<-curr;
Discovered(tmp)<-True;
Enqueue(tmp);

end if
end while

if the queue is empty and we never found the goal then
return No Path to goal

else
curr<-parent(goal);

while
curr hasn’t reached the start do

data[currRow][currCol] = ’*’;
curr<-Parent(curr);
end while

end if
end function
Duplicate post:

http://www.cplusplus.com/forum/beginner/222306/

Please don't do that.
ohk i won't do it
Topic archived. No new replies allowed.