-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetIndex.java
65 lines (59 loc) · 2.27 KB
/
GetIndex.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.util.*;
public class GetIndex
{
int hor = 0;
int ver = 0;
int value = 0;
int crawler = 0;
String test;
/*
Helper function to output indexes from a 2D Array @Lucas Perez
*/
void get2DIndex(int path[], int graph[][])
{
for (int i = 0; i < graph.length; i++)
{
for (int j = 0; j < graph[0].length; j++)
{
if (graph[i][j] == value)
{
hor = i;
ver = j;
crawler++;
print2DIndex();
}
if (crawler > path.length-1)
{
test = "test";
break;
}
else
value = path[crawler];
}
}
}
void print2DIndex()
{
System.out.println("For " + value + " the indexes are " + hor + " and " + ver);
System.out.println(test);
}
public static void main (String[] args)
{ // 0 1 2 3 4 5 6 7 8 9 10 11
int graph[][] = new int [][]{{0, 6, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0}, // 0
{2, 0, 10, 0, 0, 15, 0, 0, 0, 0, 0, 0}, // 1
{0, 6, 0, 4, 0, 0, 25, 0, 0, 0, 0, 0}, // 2
{0, 0, 10, 0, 0, 0, 0, 10, 0, 0, 0, 0}, // 3
{2, 0, 0, 0, 0, 15, 0, 0, 1, 0, 0, 0}, // 4
{0, 6, 0, 0, 5, 0, 25, 0, 0, 3, 0, 0}, // 5
{0, 0, 10, 0, 0, 15, 0, 10, 0, 0, 5, 0}, // 6
{0, 0, 0, 4, 0, 0, 25, 0, 0, 0, 0, 2}, // 7
{0, 0, 0, 0, 5, 0, 0, 0, 0, 3, 0, 0}, // 8
{0, 0, 0, 0, 0, 15, 0, 0, 1, 0, 5, 0}, // 9
{0, 0, 0, 0, 0, 0, 25, 0, 0, 3, 0, 2}, // 10
{0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 5, 0}}; // 11
GetIndex gi = new GetIndex();
int[] path = {0, 5, 1, 3, 5, 2};
gi.get2DIndex(path, graph);
gi.print2DIndex();
}
}