其实不是很懂,为什么链表要一定要说明有环,意义是什么呢。虽然程序能实现,但感觉操作意义不大。吸收到的东西不大。
package NOdeTest;
import org.w3c.dom.Node;
public class LinkIsLoop {
private Node head = null;
private Node node = null;
private Node node2 = null;
private int temp;
public void LinkIsloop(Node head) {
this.head = head;
this.node = head;
this.node2 = head.next;
this.findentrance(head);
}
private void isloop(Node head2) {
// TODO Auto-generated method stub
}
private void findentrance(Node head2) {
Node node = head2;
Node node2 = node.next;
while (node != null) {
node2 = node.next;
while (node2 != null) {
if (node == node2) {
// 说明有环
System.out.println("**************链表有环!!!***********");
System.out.println("**************链表的入口是" + node.obj+"**************");
// node2.next=node;
break;
}
node2 = node2.next;
}
if (node == node2) {
break;
}
node = node.next;
}
System.out.println("****************链表没没没有环!!**************");
}
}