I’m working on a java assignment for a class and I’m unsure how to solve this problem. I don’t want it completed for me, but get me started in the right direction. I’m mostly unsure of the recursive part of the program. I’m not very good at programming.
problem:
NorthEast paths are obtained from a
two-dimensional grid by moving up and
right. For example, in the figure
below, there are two paths from 1,0 to
0,1. The first is (1,0), (0,0), (0,1),
the second is (1,0), (1,1), (0,1).
Note that there are no NorthEast paths
from (0,1) to any other point. Also
note that there is one NorthEast path
from (1,1) to (0,1). You are to write
a program that takes a number (size of
grid – no larger than 10) and a
starting location and an ending
location and recursively computes all
of the “NorthEast” paths.
0,0 0,1
1,0 1,1
I’m reading in the file prog2.dat
which reads in the grid size first and then the starting coordinates and then finishing coordinates. for example:
5
3 0
1 3
It needs to be one files, so I’m going to use methods. If someone could get me started or direct me to a similar question already posted, I would appreciate it.
One solution involving recursion involves finding the next point on the path that will get you closest to your destination. Once you have that point, you then use the same method to figure out the next closest point and so on. This process (or the recursion) ends when you have arrived at your destination.
You can try doing something like this:
I’ve omitted a lot of details so you can figure out more for yourself, but that’s one approach to using recursion. Essentially, you’re building up a path. You’ll have to figure out how to manage your Paths, but chances are you will need to be able to push and pop points off of them.