1、先定义图的节点,节点ID和下一节点号
package dyfu.algorithm;
import java.util.LinkedList;
//图的节点
public class Node {
private Integer id; //节点
private LinkedList<Node> nextNode = null; //下一节点
private boolean isVisted = false;
public Node(Integer id) {
this.id = id ;
}
public void setId(int id) {
this.id = id ;
}
public Integer getId() {
return id;
}
public void addNextNode(Node n) {
if(nextNode == null) {
nextNode = new LinkedList<Node>();
nextNode.add(n);
}else {
nextNode.add(n);
}
}
public LinkedList<Node> getNextNode() {
return nextNode;
}
public void setIsVisted(boolean b) {
this.isVisted = b;
}
public boolean getIsVisted() {
return this.isVisted;
}
}
2、计算路径
package dyfu.algorithm;
import java.util.Set;
import java.util.Stack;
public class NodeDAGList {
private Stack<Node> stack =