Skip to content

Instantly share code, notes, and snippets.

@happyduck-git
Created June 5, 2022 11:19
Show Gist options
  • Save happyduck-git/db88119a292025f709c99b062122c653 to your computer and use it in GitHub Desktop.
Save happyduck-git/db88119a292025f709c99b062122c653 to your computer and use it in GitHub Desktop.
public Graph {
ArrayList<LinkedList<Node>> verticesAndEdges;
public Graph() {
verticesAndEdges = new ArrayList<LinkedList<Node>>();
}
public void addVertedx(Node vertex) {
LinkedList<Node> list = new LinkedList<>();
list.add(vertex);
verticesAndEdges.add(list);
}
public void addEdges(int from, int to) {
LinkedList<Node> currentList = verticesAndEdges.get(from);
Node dstNode = verticesAndEdges.get(to).get(0);
currentList.add(dstNode);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment