<commit_before>package ru.job4j.list;

import java.util.ArrayList;

/**
 * Class DetectionOfCycle.
 * @author  shustovakv (mailto: <EMAIL>)
 * @since 25.07.2018
 */
public class DetectionOfCycle {

    boolean hasCycle(Node node) {
        ArrayList<Node> list = new ArrayList<>();
        do {
            list.add(node);
            for (int i = 0; i < list.size() - 1; i++) {
                if (list.get(i) == node) {
                    return true;
                }
            }
            node = node.next;
        } while (node != null);
        return false;
    }
    public static class Node<T> {
        T value;<commit_msg>Задан связанный список. Определить цикличность.[#63209] refactoring<commit_after>package ru.job4j.list;

/**
 * Class DetectionOfCycle.
 * @author  shustovakv (mailto: <EMAIL>)
 * @since 25.07.2018
 */
public class DetectionOfCycle {

    boolean hasCycle(Node node) {
        if (node == null) {
            return false;
        }
        Node slow, fast;

        slow = fast = node;

        while (true) {

            slow = slow.next;

            if (fast.next != null) {
                fast = fast.next.next;

            } else {
                return false;
            }

            if (slow == null || fast == null) {
                return false;
            }

            if (slow == fast) {
                return true;
            }
        }
    }

    public static class Node<T> {
        T value;
{'fraction_non_alphanumeric': 0.1178082191780822, 'fraction_numerical': 0.017123287671232876, 'mean_word_length': 1.4108910891089108, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5655910', 'n_tokens_mistral': 477, 'n_tokens_neox': 439, 'n_words': 111}