Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Point
- {
- public int x, y;
- public Point(int x, int y)
- {
- this.x = x;
- this.y = y;
- }
- @Override
- public String toString()
- {
- return "(" + this.x + "," + this.y + ")";
- }
- }
- public static void findPath(int grid[][], Point start, Point end, ArrayList<Point> currentPath)
- {
- currentPath.add(start);
- if(start.x == end.x && start.y == end.y)
- {
- System.out.println(currentPath);
- return;
- }
- if(start.x + 1 < grid.length)
- {
- findPath(grid, new Point(start.x + 1, start.y), end, currentPath);
- }
- if(start.y + 1 < grid[0].length)
- {
- findPath(grid, new Point(start.x, start.y + 1), end, currentPath);
- }
- }
- [(0,0), (1,0), (1,1)]
- [(0,0), (1,0), (1,1), (0,1), (1,1)]
- [(0,0), (1,0), (1,1)]
- [(0,0), (0,1), (1,1)]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement