Ich habe mit diesem Code gekämpft. Eclipse sagt mir immer wieder, dass ich den Typ von startnode und endnode zu node ändern soll. Ich habe das getan und ich habe keine Fortschritte. Kann mir bitte jemand erklären, was ich mache, weil es schwer ist den kürzesten Weg zu bekommen. Wenn möglich, zeigen Sie mir meine Fehler und wie Sie es beheben können. Vielen Dank im VorausgetShortestPath; Wie kann ich diesen Code beheben
public List<Coordinate> getShortestPath(Coordinate start, Coordinate end) {
Coordinate start = board.get(start.getRow()).get(start.getCol()); **eclipse ask me to change type of start to node**
Coordinate end = board.get(end.getRow()).get(end.getCol());
eclipse fragen Sie mich Art von Anfang an ändern und von Ende auch
List<Coordinate> dispenser = new LinkedList<Coordinate>();
dispenser.add(start);
Map<Coordinate, Coordinate> predecessors = new HashMap<Coordinate, Coordinate>();
while (!dispenser.isEmpty()){
Coordinate current = dispenser.remove(0);
if(current == end){
break;
}//end of if
for(Coordinate n : getNeighbors(current)){
if(!predecessors.containsKey(n)){
predecessors.put(n, current);
dispenser.add(n);
return constructPath(predecessors, start, end);
}//end of while
List<Coordinate> path = new LinkedList<Coordinate>();
if (predecessors.containsKey(endNode)) {
Coordinate currNode = endNode;
while (currNode != startNode) {
path.add(0, currNode);
currNode = predecessors.get(currNode);
}//end of while
path.add(0, startNode);
}//end of if
return path;
}
List<Coordinate> shortest = new LinkedList<Coordinate>();
for (Node p: path){
shortest.add(((coordinate) p).getCoordinate()); **eclipse says cannot cast from node to coordinate** I am not so good with java, I need help *
}
return shortest;
}
Wo und wie haben Sie 'startNode' und' endNode' deklariert? Ich kann nicht herausfinden, was Eclipse Ihnen ohne diese wichtige Information zu sagen versucht. – ajb
danke für Ihre Antwort. eclipse sagt Änderungstyp des Startpunktes zum Knoten: Koordinate start = board.get (start.getRow()). get (start.getCol()); \t Koordinatenende = board.get (end.getRow()). Get (end.getCol()); – adim2
Wir wissen nicht, wie "Board" aussieht. Kann dir immer noch nicht helfen. – ajb