MCPcopy Create free account
hub / github.com/Ayush7614/Daily-Coding-DS-ALGO-Practice / makeLoop

Method makeLoop

Gfg/Java/Delete_Loop_from_LL.java:46–61  ·  view source on GitHub ↗
(Node head, int x)

Source from the content-addressed store, hash-verified

44 }
45
46 public static void makeLoop(Node head, int x) {
47 if (x == 0)
48 return;
49 Node curr = head;
50 Node last = head;
51
52 int currentPosition = 1;
53 while (currentPosition < x) {
54 curr = curr.next;
55 currentPosition++;
56 }
57
58 while (last.next != null)
59 last = last.next;
60 last.next = curr;
61 }
62
63 public static boolean detectLoop(Node head) {
64 Node hare = head.next;

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected