Ejemplo n.º 1
0
        static LLNode <int> DetectLoop(LLNode <int> head)
        {
            var p = head;
            var q = head;

            while (p != null && q != null && q.Next != null)
            {
                p = p.Next;
                q = q.Next.Next;

                if (p == q)
                {
                    //var loop = p;
                    q = head;
                    while (p == q)
                    {
                        p = p.Next;
                        q = q.Next;
                    }
                    return(p);
                }
            }
            return(null);
        }
Ejemplo n.º 2
0
 public LLNode(T data)
 {
     this.Data     = data;
     this.Previous = this.Next = null;
 }