public void Push(T data) { Node_4 <T> newNode = new Node_4 <T>(data); newNode.next = head; head = newNode; }
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"); }
public DetectLoopInLinkedListUsingHasSet() { this.head = null; }
public Node_4(T data) { this.data = data; this.next = null; }