package ru.matevosyan;

import java.util.Iterator;
import java.util.NoSuchElementException;

/**
 * CycleDetection class.
 * Created on 26.05.2017.
 * @author Matevosyan Vardan
 * @version 1.0
 */

public class CycleDetection<E> {

    private int size = 0;


    /**
     * Constructor.
     */

    public CycleDetection() {
    }

    public boolean hasCycle(Node<E> first) {
        Node<E> fast;
        Node<E> slow;
        boolean detForFastToSlow = true;

        if (first != null) {
            fast = first;
            slow = first;
        } else {
            return false;
        }

        while (fast != null) {
            if (detForFastToSlow) {
                fast = fast.next.next;
            } else {
                fast = fast.next;
            }

            if (fast == slow.next) {
                detForFastToSlow = false;
                if (fast == slow) {
                    slow = first;
                }
            }
        }
        return detForFastToSlow;
    }




    /**
     * Class Node describe linkedList entry.
     * @param <E> parameter that defined when create an instance of a class.
     */

    static class Node<E> {
        E item;
        Node<E> next;

        Node(E element, Node<E> next) {
            this.item = element;
            this.next = next;
        }

        public Node(E item) {
            this.item = item;
        }
    }

}
@@ -21,77 +21,8 @@
 n;%0A%0A
-import java.util.Iterator;%0Aimport java.util.NoSuchElementException;%0A%0A
 /**%0A
@@ -160,36 +160,8 @@
  %7B%0A%0A
-    private int size = 0;%0A%0A%0A
     
@@ -226,24 +226,216 @@
 () %7B%0A    %7D%0A%0A
+    /**%0A     * Create hasCycle method to check if Linked list have cycle detection.%0A     * @param first Node from the list.%0A     * @return true if list have cycle, else return false.%0A     */%0A%0A
     public b
@@ -487,16 +487,24 @@
 %3CE%3E fast
+ = first
 ;%0A      
@@ -517,16 +517,24 @@
 %3CE%3E slow
+ = first
 ;%0A      
@@ -587,17 +587,17 @@
  (first 
-!
+=
 = null) 
@@ -602,77 +602,8 @@
 ) %7B%0A
-            fast = first;%0A            slow = first;%0A        %7D else %7B%0A
     
@@ -657,16 +657,37 @@
 (fast !=
+ null && fast.next !=
  null) %7B
@@ -754,32 +754,66 @@
 fast.next.next;%0A
+                slow = slow.next;%0A
             %7D el
@@ -855,35 +855,58 @@
 xt;%0A            
-%7D%0A%0A
+    slow = slow.next;%0A    
             if (
@@ -917,21 +917,16 @@
  == slow
-.next
 ) %7B%0A    
@@ -941,70 +941,92 @@
     
-detForFastToSlow = false;%0A                if (fast == slow
+    return true;%0A                %7D%0A            %7D%0A%0A            if (slow == first
 ) %7B%0A
+%0A
     
@@ -1041,24 +1041,99 @@
     
-    
+return true;%0A            %7D else if (
 slow =
+=
  f
-irst
+ast)%7B%0A                detForFastToSlow = false
 ;%0A  
@@ -1138,33 +1138,45 @@
                 
-%7D
+slow = first;
 %0A            %7D%0A 
@@ -1199,32 +1199,21 @@
  return 
-detForFastToSlow
+false
 ;%0A    %7D%0A
@@ -1425,122 +1425,8 @@
 t;%0A%0A
-        Node(E element, Node%3CE%3E next) %7B%0A            this.item = element;%0A            this.next = next;%0A        %7D%0A%0A
     

change to Floyd's algorithm logic