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() {
    }

    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.
     */

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

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

}
@@ -327,24 +327,31 @@
 %0A    %7D%0A%0A    
+public 
 boolean hasC
@@ -359,19 +359,16 @@
 cle(Node
-%3CE%3E
  first) 
@@ -992,24 +992,28 @@
 Slow;%0A    %7D%0A
+%0A%0A%0A%0A
     /**%0A    
@@ -1143,24 +1143,16 @@
 */%0A%0A    
-private 
 static c
@@ -1278,16 +1278,16 @@
 lement;%0A
-
         
@@ -1313,21 +1313,92 @@
 t;%0A        %7D
+%0A%0A        public Node(E item) %7B%0A            this.item = item;%0A        %7D
 %0A    %7D%0A%0A%7D

add constructor to Node