public void Reverse() { var linkedList = new Structures.LinkedList <int>(); linkedList.Insert(2); linkedList.Insert(3); linkedList.Insert(4); linkedList.Insert(5); linkedList.Reverse(); linkedList.Iterate(c => Console.WriteLine(c.Value)); }
public void MiddleNode() { var linkedList = new Structures.LinkedList <int>(); linkedList.Insert(1); linkedList.Insert(2); linkedList.Insert(3); linkedList.Insert(4); linkedList.Insert(5); ListNode <int> mid = linkedList.Middle(); Assert.AreEqual(3, mid.Value); }
public void RemoveDuplicates() { var linkedList = new Structures.LinkedList <int>(); linkedList.Insert(5); linkedList.Insert(5); linkedList.Insert(5); linkedList.Insert(5); linkedList.RemoveDuplicatesNoAux(); linkedList.Iterate(c => Console.WriteLine(c.Value)); }
public void ReverseNoRecursion() { var linkedList = new Structures.LinkedList <int>(); linkedList.Insert(2); linkedList.Insert(3); linkedList.Insert(4); linkedList.Insert(5); Printer.Print(linkedList); linkedList.ReverseNoRecursion(); Printer.Print(linkedList); }
private static ListNode <int> FindLoopNode(Structures.LinkedList <int> linkedList) { var slow = linkedList.Head(); var fast = linkedList.Head(); while (fast != null && fast.Next != null) { slow = slow.Next; fast = fast.Next.Next; if (slow == fast) { return(slow); } } return(null); // var dic = new Dictionary<ListNode<int>, int>(); // return FindLoopNode(linkedList.Head(), dic); }
public void FindLoop() { var linkedList = new Structures.LinkedList <int>(); linkedList.Insert(2); linkedList.Insert(3); linkedList.Insert(4); linkedList.Insert(5); linkedList.Insert(10); linkedList.Insert(12); linkedList.Insert(13); linkedList.Insert(14); linkedList.Insert(20); linkedList.Insert(30); ListNode <int> fail = linkedList.Find(13); fail.Next = fail; ListNode <int> loop = FindLoopNode(linkedList); Assert.AreEqual(fail.Value, loop.Value); }
public Stack() { this._stack = new Structures.LinkedList <T>(); }
public Queue() { this._queue = new Structures.LinkedList <T>(); }