I want to find all cycles in graph and using this solution Finding all cycles in undirected graphs
algorithm works fine, but I want to pass two dimensional array as argument, but there comes in a problem:
the given graph is declared like
static int[][] graph =
{
{1, 7}, {1, 8}, {7, 8}, {2, 3},
{3, 4}, {6, 4},
{7, 6}, {8, 7}
};
and it works, but I used
int[][] intGraph = new int[500][4];
.....
intGraph[j][0] = Integer.parseInt(edge[i]);
intGraph[j][1] = Integer.parseInt(edge[i+1]);
intGraph[j][2] = Integer.parseInt(edge[i+2]);
....
both array values I can accsess via arrayname[x][y]
but when I'm trying to pass it as an argument in: (all algorithm in link above)
public GraphCycleFinder(int[][] graphs) {
graph = graphs;
for (int i = 0; i < graph.length; i++){
System.out.println(i); //added to check itterations
for (int j = 0; j < graph[i].length; j++)
{
//System.out.print(graph[i][j]);
findNewCycles(new int[] {graph[i][j]});
}
}
I get no result, no errors. When I print out i values (to check how far it iterates), it gives me 0 when it loops through my array (but should be from 0 to 500), but prints from 0 to array length this hard-coded array.
I suppose that there is something with array declarations because I tried
int[][] intGraph;
and then put values like
intGraph[j][0] = Integer.parseInt(edge[i]);
but I got java.lang.NullPointerException
Any ideas?
P.s. sorry if too stupid question, I'm new in java.
UPDATE
Problem is not with array declaration. I commented out findNewCycles(new int[] {graph[i][j]});
and bouth cycles gave necessary result. Probably method findNewCycles
in this algorithm can't handle this big array. :( although only 200 vertex and 500 edges. Not much.