()
| 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) { |
nothing calls this directly
no outgoing calls
no test coverage detected