I’m having quite a bit of problem deciding how to represent a certain problem. Basically, I’ll need a list/vector with a given number from args[1]. Each of them will have from 0 up till some args[2].
I’ll need to make an algorithm to search all possible combinations of arguments from the elements within the first one.
As an example:
1 -> 3 5
2 -> 1 3 4 5
3 -> 2
4 -> 2 5 1
5 -> 1 3 4
From this example, I’ll have to generate all the combination of paths, like from 1 you can go to 3 or 5 and so on and cant go back through the same mini path so I’m guessing I’ll have to figure out some recursive way to fully search all paths.
My first attemp was to make a vector for 1 to 5 with arraylist for each element but I’m having problem initializing and accessing values withing the lists.
for (int i=0; i < total; i++) {
matrix[i] = new ArrayList<int>(total);
}
for (int i=0; i < total_paths; i++) {
matrix[Integer.parseInt(args[i])].add(Integer.parseInt(args[i]));
}
Any suggestions are welcome.
You can’t have an
ArrayList<int>; only anArrayList<Integer>. However, Java will automatically convert betweenintandIntegerfor you in most cases.