My method "addEdge" adds a node to the adjacency list of the selected node, but I want the method to add the selected node to its adjacency list as well and turn it into an undirected graph.
public class Main {
public static void main(String[] args) {
Graph g = new Graph();
Node n1 = new Node("A");
Node n2 = new Node("B");
Node n3 = new Node("C");
Node n4 = new Node("D");
n1.addEdge(n2);
n2.addEdge(n3);
n3.addEdge(n4);
n4.addEdge(n1);
}
}
class Node{
String node;
boolean isVisited;
LinkedList<Node> edge;
Node(String node){
this.node = node;
edge = new LinkedList<>();
}
public void addEdge(Node node){
edge.add(node);
}
public LinkedList<Node> getEdge(){
return edge;
}
}