Я практикую Java в школе, и сейчас у меня проблемы.
Это мой файл Graph.java:
package graph;
public interface Graph<V>{
public boolean hasEdge(V one, V two);
public void addNode(V other);
public void addEdge(V other);
}
А это мой файл UndirectedGraph.java:
package graph.undirected;
import graph.*;
import java.util.*;
public class UndirectedGraph<V> implements Graph<V>{
private HashMap<V,V> neighbourList;
private TreeMap<V,V> prev;
private TreeMap<V,Integer> dist;
public UndirectedGraph(){
neighbourList = new HashMap<V,V>();
prev = new TreeMap<V,V>();
dist = new TreeMap<V,Integer>();
}
public boolean hasEdge(V one, V two){
if(!(this.neighbourList.containsKey(one) && this.neighbourList.containsKey(two))){
throw new java.util.NoSuchElementException("Nonexistent node.");
}
else{
if( one.neighbourList.containsKey(two) && two.neighbourList.containsKey(one) ){
return false;
}
return true;
}
}
public void addNode(V other){
if(!(this.neighbourList.containsKey(other))){
// some code will come here
}
}
public void addEdge(V other){
if(!(this.neighbourList.containsKey(other))){
// and some code will come here too
}
}
}
И я получил следующие ошибки:
graph \ unirected \ UndirectedGraph.java: 23: ошибка: не удается найти символ if (one.neighbourList.containsKey (two) && two.neighbourList.containsKey (one)) {^ symbol: variable neighbourList location: variable one of type V where V является переменной типа: V расширяет объект, объявленный в классе UndirectedGraph graph \ undirected \ UndirectedGraph.java: 23: error: не удается найти символ if (one.neighbourList.containsKey (two) && two.neighbourList.containsKey (one)) {^ символ: переменная neighbourList расположение: вторая переменная типа V
где V - это тип-переменная: V расширяет объект, объявленный в классе UndirectedGraph 2, ошибки
И я застрял здесь. Может кто-нибудь помочь мне?
V
не имеет участникаneighbourList
- person xingbin   schedule 19.05.2018