Exemplo n.º 1
0
 public Enumerator(DoubleLinkedList <T> dlnodes)
 {
     _dlnodes = dlnodes;
 }
 internal static void Max(this DoubleLinkedList <int> source)
 {
     Console.WriteLine("调用Max()方法");
 }
Exemplo n.º 3
0
        public static void call()
        {
            #region 双向链表
            ////12,----双向链表
            ////----在后面添加节点
            DoubleLinkedList <int> doubleLinkedList = new DoubleLinkedList <int>();
            //DLinkNode<int> firstNode = new DLinkNode<int> { Content = 1 };
            //doubleLinkedList.AddOnTail(firstNode);
            ////case-1 => 1
            //Console.WriteLine(doubleLinkedList.Count == 1);
            ////case-1 => true
            //Console.WriteLine(firstNode == doubleLinkedList.Head);
            ////case-1 => true
            //Console.WriteLine(firstNode == doubleLinkedList.Tail);

            //DLinkNode<int> secondNode = new DLinkNode<int> { Content = 2 };
            //doubleLinkedList.AddOnTail(secondNode);

            ////case-2 =>node_2 的上一个节点是链表的头结点;
            //Console.WriteLine(secondNode.Previous == doubleLinkedList.Head);
            ////case-2 =>node_1 的下一个节点是node_2;
            //Console.WriteLine(firstNode.Next == secondNode);
            ////case-2 => 2
            //Console.WriteLine(doubleLinkedList.Count == 2);
            ////case-2 => 第一个节点仍然是头节点
            //Console.WriteLine(firstNode == doubleLinkedList.Head);
            ////case-2 => tail is node_2
            //Console.WriteLine(secondNode == doubleLinkedList.Tail);

            //DLinkNode<int> thirdNode = new DLinkNode<int> { Content = 3 };
            //doubleLinkedList.AddOnTail(thirdNode);
            ////case-3 =>node_3 的上一个节点是node_2;
            //Console.WriteLine(thirdNode.Previous == secondNode);
            ////case-3 =>node_2 的下一个节点是node_3;
            //Console.WriteLine(secondNode.Next == thirdNode);
            ////case-3 => 3
            //Console.WriteLine(doubleLinkedList.Count == 3);
            ////case-3 => true
            //Console.WriteLine(firstNode == doubleLinkedList.Head);
            ////case-3 => tail is node_3
            //Console.WriteLine(thirdNode == doubleLinkedList.Tail);
            ////case-3 => node_2 isn't tail
            //Console.WriteLine(secondNode != doubleLinkedList.Head &&
            //    secondNode != doubleLinkedList.Tail);

            ////case-4 => 4
            //DLinkNode<int> fourthNode = new DLinkNode<int> { Content = 4 };
            //doubleLinkedList.AddOnTail(fourthNode);
            //Console.WriteLine(doubleLinkedList.Count == 4);

            //Console.WriteLine("----从头添加节点");

            //DLinkNode<int> fifthNode = new DLinkNode<int> { Content = 5 };
            //doubleLinkedList.AddOnHead(fifthNode);
            ////case-1 => 5
            //Console.WriteLine(doubleLinkedList.Head == fifthNode);
            //Console.WriteLine(doubleLinkedList.Count == 5);

            //Console.WriteLine("-----删除firstNode之前");
            //Console.WriteLine(firstNode.Previous == doubleLinkedList.Head);
            //Console.WriteLine(doubleLinkedList.Head.Next == firstNode);
            //Console.WriteLine(firstNode.Next == secondNode);
            //Console.WriteLine(secondNode.Previous == firstNode);
            //doubleLinkedList.Remove(firstNode);
            //Console.WriteLine("-----删除firstNode之后");
            //Console.WriteLine(doubleLinkedList.Count == 4);
            //Console.WriteLine(firstNode.Previous == null);
            //Console.WriteLine(firstNode.Next == null);
            //Console.WriteLine(fifthNode.Next == secondNode);
            //Console.WriteLine(secondNode.Previous == fifthNode);

            //Console.WriteLine("--删除fifthNode(头结点)之前");
            //Console.WriteLine(fifthNode.Previous == null);
            //Console.WriteLine(fifthNode.Next == secondNode);
            //Console.WriteLine(secondNode.Previous == fifthNode);
            //doubleLinkedList.Remove(fifthNode);
            //Console.WriteLine("-----删除fifthNode(头结点)之后");
            //Console.WriteLine(doubleLinkedList.Count == 3);
            //Console.WriteLine(fifthNode.Previous == null);
            //Console.WriteLine(fifthNode.Next == null);
            //Console.WriteLine(doubleLinkedList.Head == secondNode);
            //Console.WriteLine(secondNode.Previous == null);

            //Console.WriteLine("--删除fourthNode(尾节点)之前");
            //Console.WriteLine(fourthNode.Previous == thirdNode);
            //Console.WriteLine(fourthNode.Next == null);
            //Console.WriteLine(thirdNode.Next == fourthNode);
            //doubleLinkedList.Remove(fourthNode);
            //Console.WriteLine("--删除fourthNode(尾节点)之后");
            //Console.WriteLine(doubleLinkedList.Count == 2);
            //Console.WriteLine(fourthNode.Previous == null);
            //Console.WriteLine(fourthNode.Next == null);
            //Console.WriteLine(thirdNode.Next = null);

            //doubleLinkedList.Remove(thirdNode);
            //doubleLinkedList.Remove(secondNode);
            //Console.WriteLine("-- 删除所有节点");
            //Console.WriteLine(doubleLinkedList.Count == 0);
            //Console.WriteLine(doubleLinkedList.Head == null);
            //Console.WriteLine(doubleLinkedList.Tail == null);

            //Console.WriteLine("---------------");


            ////----节点数量
            ////Console.WriteLine($"节点数量=>{doubleLinkedList._count}");

            //////----在后面插入
            ////DLinkNode<int> sixthNode = new DLinkNode<int> { Content = 6 };
            ////doubleLinkedList.Insert(firstNode,sixthNode);
            //////case => 6
            ////Console.WriteLine($"Insert=>{doubleLinkedList.Head.Next.Next.Content}");

            //////----交换
            /////----5,1,6,2,3,4
            /////----首个和中间第5个交换
            ////Console.WriteLine("首个和中间第5个交换");
            //////case-1 => 5
            ////Console.WriteLine($"交换{doubleLinkedList.Head.Content}");
            //////case-1 => 3
            ////Console.WriteLine(doubleLinkedList.Head.Next.Next.Next.Next.Content);
            ////doubleLinkedList.Swap(thirdNode, fifthNode);
            //////case-1 => 3
            ////Console.WriteLine(doubleLinkedList.Head.Content);
            //////case-1 => 5
            ////Console.WriteLine(doubleLinkedList.Head.Next.Next.Next.Next.Content);

            //////----首尾交换
            ////Console.WriteLine("首尾交换");
            //////case-2 => 5
            ////Console.WriteLine(doubleLinkedList.Head.Content);
            //////case-2 => 4
            ////Console.WriteLine(doubleLinkedList.Head.Next.Next.Next.Next.Next.Content);
            ////doubleLinkedList.Swap(fourthNode, fifthNode);
            //////case-2 => 4
            ////Console.WriteLine(doubleLinkedList.Head.Content);
            //////case-2 => 5
            ////Console.WriteLine(doubleLinkedList.Head.Next.Next.Next.Next.Next.Content);

            //////----末尾和中间第3个交换
            ////Console.WriteLine("末尾和中间第3个交换");
            //////case-3 => 6
            ////Console.WriteLine(doubleLinkedList.Head.Next.Next.Content);
            //////case-3 => 4
            ////Console.WriteLine(doubleLinkedList.Head.Next.Next.Next.Next.Next.Content);
            ////doubleLinkedList.Swap(fourthNode, sixthNode);
            //////case-3 => 4
            ////Console.WriteLine(doubleLinkedList.Head.Next.Next.Content);
            //////case-3 => 6
            ////Console.WriteLine(doubleLinkedList.Head.Next.Next.Next.Next.Next.Content);

            //////----中间相隔交换
            ////Console.WriteLine("----中间相隔交换");
            //////case-7 => 1
            ////Console.WriteLine(doubleLinkedList.Head.Next.Content);
            //////case-7 => 3
            ////Console.WriteLine(doubleLinkedList.Head.Next.Next.Next.Next.Content);
            ////doubleLinkedList.Swap(firstNode, thirdNode);
            //////case-7 => 1
            ////Console.WriteLine(doubleLinkedList.Head.Next.Content);
            //////case-7 => 3
            ////Console.WriteLine(doubleLinkedList.Head.Next.Next.Next.Next.Content);

            //////----中间相邻交换
            ////Console.WriteLine("----中间相邻交换");
            //////case-4 => 2
            ////Console.WriteLine(doubleLinkedList.Head.Next.Next.Next.Content);
            //////case-4 => 3
            ////Console.WriteLine(doubleLinkedList.Head.Next.Next.Next.Next.Content);
            ////doubleLinkedList.Swap(secondNode, thirdNode);
            //////case-4 => 3
            ////Console.WriteLine(doubleLinkedList.Head.Next.Next.Next.Content);
            //////case-4 => 2
            ////Console.WriteLine(doubleLinkedList.Head.Next.Next.Next.Next.Content);

            //////----末尾相邻交换
            ////Console.WriteLine("----末尾相邻交换");
            //////case-5 => 3
            ////Console.WriteLine(doubleLinkedList.Head.Next.Next.Next.Next.Content);
            //////case-5 => 4
            ////Console.WriteLine(doubleLinkedList.Head.Next.Next.Next.Next.Next.Content);
            ////doubleLinkedList.Swap(fourthNode, thirdNode);
            //////case-5 => 4
            ////Console.WriteLine(doubleLinkedList.Head.Next.Next.Next.Next.Content);
            //////case-5 => 3
            ////Console.WriteLine(doubleLinkedList.Head.Next.Next.Next.Next.Next.Content);

            //////----头部相邻交换
            ////Console.WriteLine("----头部相邻交换");
            //////case-6 => 5
            ////Console.WriteLine(doubleLinkedList.Head.Content);
            //////case-6 => 1
            ////Console.WriteLine(doubleLinkedList.Head.Next.Content);
            ////doubleLinkedList.Swap(firstNode, fifthNode);
            //////case-6 => 5
            ////Console.WriteLine(doubleLinkedList.Head.Content);
            //////case-6' => 1
            ////Console.WriteLine(doubleLinkedList.Head.Next.Content);

            //#endregion

            #endregion
        }