コード例 #1
0
        public static void TestCloneRandomPointer()
        {
            SLLNode root = new SLLNode {
                Data = 10
            };

            root.Next = new SLLNode {
                Data = 15
            };
            root.Next.Next = new SLLNode {
                Data = 25
            };
            root.Next.Next.Next = new SLLNode {
                Data = 40
            };
            root.Random                = root.Next.Next;
            root.Next.Random           = root;
            root.Next.Next.Random      = root.Next;
            root.Next.Next.Next.Random = root.Next;

            SLList list = new SLList {
                Head = root
            };

            list.Display();

            SLLNode result = list.ClonewithRandomPointer();


            SLList list2 = new SLList {
                Head = result
            };

            list2.Display();
        }
コード例 #2
0
        public static void TestSLL()
        {
            SLList list = new SLList();

            list.InsertAtBegining(10);
            list.InsertAtBegining(20);
            list.InsertAtBegining(30);
            list.InsertAtBegining(40);
            list.InsertAtBegining(50);


            list.Display();

            Console.WriteLine("Swapping pairwise");


            // To be fixed: ist.PairwiseSwap();
            list.DeleteAlternetNodes();

            ////Console.WriteLine(list.GetNthNode(5));

            //Console.WriteLine(" Middle element" + list.GetMiddle().Data);

            //Console.WriteLine("5th from end " + list.GetNthNodeFromEndUsingTwoPointer(1).Data);

            //list.ReverseList();
            //Console.WriteLine("Reversed list");
            list.Display();



            // Console.WriteLine(" is Palindrom" + list.IsPalindrom());

            //TestCloneRandomPointer();
        }
コード例 #3
0
        static void Main(string[] args)
        {
            var list = new SLList <int>();

            list.AddLast(1);
            list.AddLast(2);
            list.AddLast(3);
            list.AddLast(4);
            for (int i = 0; i < list.size; i++)
            {
                Console.Write(list[i] + " ");
            }
            Console.WriteLine();

            list.RemoveAt(2);
            for (int i = 0; i < list.size; i++)
            {
                Console.Write(list[i] + " ");
            }
            Console.WriteLine();

            list.AddFirst(5);
            for (int i = 0; i < list.size; i++)
            {
                Console.Write(list[i] + " ");
            }
            Console.WriteLine();

            Console.WriteLine(list.IndexOf(2) + "\n");

            Console.WriteLine("null");


            var list1 = new SLList <int>();

            list1.AddLast(1);
            list1.AddLast(2);
            list1.AddLast(3);
            Console.WriteLine(list1.IndexOf(2) + "\n");

            Console.ReadLine();
        }