示例#1
0
        public void Push(T data)
        {
            Node_4 <T> newNode = new Node_4 <T>(data);

            newNode.next = head;
            head         = newNode;
        }
示例#2
0
        public void DetectLoop()
        {
            HashSet <Node_4 <T> > hash = new HashSet <Node_4 <T> >();

            while (head != null)
            {
                if (hash.Contains(head))
                {
                    Console.WriteLine($"Loop Detects at {head.data}");
                    return;
                }
                hash.Add(head);
                head = head.next;
            }
            Console.WriteLine($"Loop not Found");
        }
示例#3
0
 public DetectLoopInLinkedListUsingHasSet()
 {
     this.head = null;
 }
示例#4
0
 public Node_4(T data)
 {
     this.data = data;
     this.next = null;
 }