(Node head, int x)
| 77 | } |
| 78 | |
| 79 | public static void makeLoop(Node head, int x){ |
| 80 | if (x == 0) |
| 81 | return; |
| 82 | Node curr = head; |
| 83 | Node last = head; |
| 84 | |
| 85 | int currentPosition = 1; |
| 86 | while (currentPosition < x) |
| 87 | { |
| 88 | curr = curr.next; |
| 89 | currentPosition++; |
| 90 | } |
| 91 | |
| 92 | while (last.next != null) |
| 93 | last = last.next; |
| 94 | last.next = curr; |
| 95 | } |
| 96 | |
| 97 | public static boolean detectLoop(Node head){ |
| 98 | Node hare = head.next; |