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); }
public LLNode(T data) { this.Data = data; this.Previous = this.Next = null; }