static void Main(string[] args)
        {
            MyLinkedList list = new MyLinkedList();

            list.addLast(10);
            list.addLast(20);
            list.addLast(30);
            list.addLast(40);
            list.addLast(50);
            list.addLast(60);
            list.addLast(70);

            Console.WriteLine("Middle node is :" + list.printMiddle(list));

            Console.WriteLine("index is " + list.indexOf(40));
            Console.WriteLine("index is " + list.indexOf(300));
            Console.WriteLine("contains " + list.contains(300));


            Console.WriteLine(list.getSize());
            var arrays = list.toArray(list);

            Console.WriteLine("toArray :" + list.printArray(arrays));


            list.Reverse(list);
            Console.WriteLine("Reverse :" + list.printLinkedList(list));


            list.DeleteFirst();

            Console.WriteLine("Kth node from end " + list.getKthFromTheEnd(4));

            Console.WriteLine("Does old list has loop ? " + list.hasLoop());

            var newList = list.CreateListWithLoop();

            Console.WriteLine("Does new list has loop ? " + newList.hasLoop());


            //-----------------LinkedListQueue ---------------------------//

            LinkedListQueue lq = new LinkedListQueue();

            lq.enqueue(10);
            lq.enqueue(20);
            lq.enqueue(30);

            var removedItem = lq.dequeue();

            Console.WriteLine("Item removed from LinkedListQueue is :" + removedItem);

            Console.WriteLine("Item to peek from LinkedListQueue is :" + lq.peek());

            Console.WriteLine("Is LinkedListQueue empty?: " + lq.isEmpty());

            Console.ReadLine();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            MyLinkedList <int> list = new MyLinkedList <int>();

            list.InsertAfter(11);
            list.InsertFirst(5);
            list.InsertFirst(6);
            list.InsertFirst(7);
            list.InsertAfter(1);
            list.InsertAfter(81);
            list.InsertAfter(10);
            list.InsertAfter(-1);

            list.DeleteFirst();
            list.DeleteAfter();


            Node <int> node = list.GetNode(7);

            if (node == null)
            {
                Console.WriteLine("Element is  apsent");
            }
            else
            {
                Console.WriteLine("Elemetn  is   present");
            }



            Console.WriteLine("Lenght =  {0}", list.length);



            Console.ReadKey();
        }