2
Hello, I’m starting to see graphs now, I’m trying to create a program where the user enters with an adjacency matrix and the program calculates the shortest possible path from the initial node to the end and that all edges have the same weight, but I couldn’t find a way for the program to know that it reached the last node, so I’ll compare it to the auxiliary variable to know which is the shortest path
I’ve done this so far:
static int tCaminho = 100, tAux = 0;
static int[][] ma = new int[8][8];
static Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
// TODO Auto-generated method stub
for (int i = 0; i < 8; ++i) {
for (int j = 0; j < 8; ++j) {
ma[i][j] = scan.nextInt();
}
}
caminho(0 , 0);
System.out.println(tCaminho);
}
public static void caminho(int c, int cc){
for(int j = cc; j < 8; ++j){
if(ma[c][j] == 1){
++tAux;
caminho(c+1, 0);
}
if(j == 7){
if(tAux < tCaminho){
tCaminho = tAux;
}
tAux = 0;
}
}
}
Someone could help (if you’re doing too much shit talk, I’m studying on my own)
Welcome to Stack Overflow en =). I hope you like the site and the community!
– Sérgio Mucciaccia