Hello,
Im trying to solve the infamous Traveling Salesman problem for my java class.
Basically what im doing is looping through the columns and rows of a 2-dimensional array and then trying to store the smallest value in the row/column in a method that i can later print to screen.
Here is the portion of the loop that is passing the info to the distanceTraveled method to add to the total distance travaled:
if ( a[ row ][ column ] == min )
{
int tempDist= a[ row ][ column ];
distanceTraveled( tempDist );
return column;
}
And here is the distanceTraveled method:
public static int DistanceTraveled ( int distance )
{
int total =+ distance;
return total;
}
...both files are in the same class. I would like to have the DistanceTraveled method add up the distances, but this is not happening since it is expecting an argument and if I pass a 0 just to call it it will return a 0.
So, my question, is how do I implement a counter that adds up the distances so I can return the total distance later in my program.
Thanks in advance!
Im trying to solve the infamous Traveling Salesman problem for my java class.
Basically what im doing is looping through the columns and rows of a 2-dimensional array and then trying to store the smallest value in the row/column in a method that i can later print to screen.
Here is the portion of the loop that is passing the info to the distanceTraveled method to add to the total distance travaled:
if ( a[ row ][ column ] == min )
{
int tempDist= a[ row ][ column ];
distanceTraveled( tempDist );
return column;
}
And here is the distanceTraveled method:
public static int DistanceTraveled ( int distance )
{
int total =+ distance;
return total;
}
...both files are in the same class. I would like to have the DistanceTraveled method add up the distances, but this is not happening since it is expecting an argument and if I pass a 0 just to call it it will return a 0.
So, my question, is how do I implement a counter that adds up the distances so I can return the total distance later in my program.
Thanks in advance!