如何判断环的存在?
flcab 2000-12-30 03:17:00 //file edge.java
public class edge
{
String father_code;
String child_code;
public edge(String s1,String s2)
{
father_code=s1;
child_code=s2;
}
public static void main(String[] args){
edge graph[]=new edge[10];
graph[0]=new edge("001","002");
graph[1]=new edge("002","003");
graph[2]=new edge("003","004");
graph[3]=new edge("001","004");
graph[4]=new edge("002","004");
graph[5]=new edge("005","006");
graph[6]=new edge("006","007");
graph[7]=new edge("004","005");
graph[8]=new edge("007","002");
graph[9]=new edge("006","008");
}
}
问题是,如何判断edge[]数组中存在环?
例如上例中存在环 "002"->"004"->"005"->"006"->"007"->"002"...