hi everyone, i currently have code which allows me to take the name of a place from an array, then find the next smallest distance away from it (found in a 2d array) and then find the place that this leads to. I have this on loop however im having problems when i try to ensure that no cycles are made, aka that the program never returns to the same place even if it is the next smallest distance. Below is my method for this, although it compiles fine can anyone tell me if they think it will work. My problem is with the method calls of this from another file but id first like to try and establish if this is ok to start with.
"if (igNode == n[l])" will never, never be true, because igNode is a brand new String, created just before, that can't possibly be the value of n.
If you mean to check whether n is a zero-length String, or more generally, has a specific String value, then you must use the equals() method, not "==", like "if (ifNode.equals(n))..."
Now, with that out of the way, the statement controlled by the "if" is the empty set of braces right after -- i.e., you've written "if (impossible thing) then do nothing." The next two statements that assign values to your two-element array are always executed. Nowhere do I see anything that looks like searching for cycles.
If you've got trees of connected nodes with names and links, shouldn't you have a "Node" class with a "name" property, some "next" and "prev" or "right" and "left" properties, and various useful methods for linking, unlinking, searching, etc defined inside?