Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. class Point
  2. {
  3. public int x, y;
  4.  
  5. public Point(int x, int y)
  6. {
  7. this.x = x;
  8. this.y = y;
  9. }
  10.  
  11. @Override
  12. public String toString()
  13. {
  14. return "(" + this.x + "," + this.y + ")";
  15. }
  16. }
  17.  
  18. public static void findPath(int grid[][], Point start, Point end, ArrayList<Point> currentPath)
  19. {
  20. currentPath.add(start);
  21.  
  22. if(start.x == end.x && start.y == end.y)
  23. {
  24. System.out.println(currentPath);
  25. return;
  26. }
  27.  
  28. if(start.x + 1 < grid.length)
  29. {
  30. findPath(grid, new Point(start.x + 1, start.y), end, currentPath);
  31. }
  32.  
  33. if(start.y + 1 < grid[0].length)
  34. {
  35. findPath(grid, new Point(start.x, start.y + 1), end, currentPath);
  36. }
  37.  
  38. }
  39.  
  40. [(0,0), (1,0), (1,1)]
  41. [(0,0), (1,0), (1,1), (0,1), (1,1)]
  42.  
  43. [(0,0), (1,0), (1,1)]
  44. [(0,0), (0,1), (1,1)]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement