package by.vorokhobko.List;

/**
 * CyclicalLinkedList.
 *
 * Class CyclicalLinkedList to determine the cyclical for 005_Pro, lesson 3.
 * @author Evgeny Vorokhobko (vorokhobko2011@yandex.ru).
 * @since 28.06.2017.
 * @version 1.
 * @param <T>.
 */
public class CyclicalLinkedList<T> {
    /**
     * Node.
     *
     * Class Node for start CyclicalLinkedList 005_Pro, lesson 3.
     * @param <T>.
     */
    public static class Node<T> {
        /**
         * The class field.
         */
        private T value;
        /**
         * The class field.
         */
        private Node<T> next;
        /**
         * Add constructor.
         * @param value - value.
         */
        public Node(T value) {
            this.value = value;
        }
        /**
         * Add setter nextElement.
         * @param next - next.
         */
        public void setNext(Node<T> next) {
            this.next = next;
        }
        /**
         * Add getter next.
         * @return tag.
         */
        public Node<T> getNext() {
            return next;
        }
    }
    /**
     * Method return true if have cycle.
     * @param first - first.
     * @return tag.
     */
    public boolean hasCycle(Node first) {
        boolean isNeedSave = false;
        Node count = first.getNext();
        if (first == null) {
            isNeedSave = false;
        }
        while ((first = count) != null) {
            if (first.equals(count)) {
                isNeedSave = true;
                break;
            }
        }
        return isNeedSave;
    }
}
@@ -1303,79 +1303,8 @@
 ();%0A
-        if (first == null) %7B%0A            isNeedSave = false;%0A        %7D%0A
     
@@ -1345,47 +1345,8 @@
 ) %7B%0A
-            if (first.equals(count)) %7B%0A
     
@@ -1403,22 +1403,8 @@
 ak;%0A
-            %7D%0A
     

update 5.3.4. Задан связанный список. Определить цикличность.[#18058]