public void DeleteDoubleLinkedList() { DoubleLinkedList dll = new DoubleLinkedList(); FibonacciNode n1 = new FibonacciNode() { StationID = 1 }; FibonacciNode n2 = new FibonacciNode() { StationID = 2 }; FibonacciNode n3 = new FibonacciNode() { StationID = 3 }; dll.Add(n1); dll.Add(n2); dll.Add(n3); Assert.AreEqual(1, dll.head.StationID); Assert.AreEqual(2, dll.head.RightNode.StationID); Assert.AreEqual(3, dll.head.RightNode.RightNode.StationID); Assert.AreEqual(1, dll.head.LeftNode.RightNode.StationID); dll.Delete(n3); Assert.AreEqual(1, dll.head.StationID); Assert.AreEqual(2, dll.head.RightNode.StationID); Assert.AreEqual(1, dll.head.LeftNode.RightNode.StationID); dll.Delete(n1); Assert.AreEqual(2, dll.head.StationID); Assert.AreEqual(2, dll.head.RightNode.StationID); }
//remove node y from root list, and link node y to x public void Link(DoubleLinkedList root, FibonacciNode y, FibonacciNode x) { root.Delete(y); //add y as a child of x if (x.Child == null) { y.Parent = x; x.Child = y; y.RightNode = y; y.LeftNode = y; } else { FibonacciNode lastNode = x.Child.LeftNode; lastNode.RightNode = y; y.RightNode = x.Child; y.LeftNode = lastNode; x.Child.LeftNode = y; y.Parent = x; } x.Degree++; y.Mark = false; }