Pop the top node and move to the left , right , top , down or retract back according the value of node 's  dir variable.
temp = s . peek ( ) ; int d = temp . getDir ( ) ; i = temp . getX ( ) ; j = temp . getY ( ) ;