MCPcopy Create free account
hub / github.com/apna-college/Alpha / removeCycle

Method removeCycle

12_LinkedList.java/LL.java:231–255  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

229 }
230
231 public Node removeCycle() {
232 Node slow = head;
233 Node fast = head;
234 int flag = 0;
235 while(fast!=null && fast.next!=null) {
236 fast = fast.next.next;
237 slow = slow.next;
238 if(fast == slow) {
239 flag = 1;
240 break;
241 }
242 }
243
244 if(flag == 0)
245 return null;
246 slow = head;
247 int i = 0;
248 while(slow != fast) {
249 slow = slow.next;
250 fast = fast.next;
251 i++;
252 }
253
254 return slow;
255 }
256
257 private Node mergeSortHelper(Node head) {
258 if(head == null || head.next == null) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected