MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / detectLoop

Method detectLoop

Programs/RemoveloopinLinkedList.java:97–107  ·  view source on GitHub ↗
(Node head)

Source from the content-addressed store, hash-verified

95 }
96
97 public static boolean detectLoop(Node head){
98 Node hare = head.next;
99 Node tortoise = head;
100 while( hare != tortoise )
101 {
102 if(hare==null || hare.next==null) return false;
103 hare = hare.next.next;
104 tortoise = tortoise.next;
105 }
106 return true;
107 }
108
109 public static int length(Node head){
110 int ret=0;

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected