Example #1
0
        static void Main(string[] args)
        {
            SoftuniLinkedListFastReverse list = new SoftuniLinkedListFastReverse();

            for (int i = 0; i < 10; i++)
            {
                list.AddLast(new Node(i + 1));
            }

            list.Reverse();
            list.Reverse();
            list.Reverse();
            list.Reverse();

            list.Foreach((node) =>
            {
                Console.WriteLine(node.Value);
            });

            SoftuniLinkedList linkedList = new SoftuniLinkedList();

            Console.WriteLine("Remove empty head: " + linkedList.RemoveHead());

            for (int i = 0; i < 3; i++)
            {
                linkedList.AddHead(new Node(i));
            }
            for (int i = 0; i < 3; i++)
            {
                linkedList.AddLast(new Node(i));
            }

            Console.WriteLine("Remove head: " + linkedList.RemoveHead().Value);

            Console.WriteLine("Remove Tail: " + linkedList.RemoveTail().Value);

            var currentNode = linkedList.Tail;


            Console.WriteLine("Foreach from head:");

            linkedList.ForeachFromHead((node) =>
            {
                Console.WriteLine($"From action: {node.Value}");
            });

            Console.WriteLine("Foreach from Tail:");

            linkedList.ForeachFromTail((node) =>
            {
                Console.WriteLine($"From action: {node.Value}");
            });

            int[] linkedListAsArray = linkedList.ToArray();
        }
Example #2
0
        static void Main(string[] args)
        {
            Node node = new Node(1);
            SoftuniLinkedList linkedList = new SoftuniLinkedList();

            for (int i = 0; i < 20; i++)
            {
                linkedList.AddHead(new Node(i));
            }
            var currentNode = linkedList.Tail;

            while (currentNode != null)
            {
                Console.WriteLine(currentNode.Value);
                currentNode = currentNode.Previous;
            }
        }
        static void Main(string[] args)
        {
            MusicLinkedList <int> playList = new MusicLinkedList <int>();

            while (true)
            {
                Console.WriteLine("Add music to playlist src: ");
                string srcInput = Console.ReadLine();
                if (srcInput == "end")
                {
                    break;
                }

                int src = int.Parse(srcInput);

                playList.AddLast(new NodeMusic <int>(src));
            }

            playList.ForeachFromHead(s => Console.WriteLine(s.Value));

            //playList.ForeachFromHead((node) =>
            //{
            //    Console.WriteLine($"Now playing: {node.Value}");
            //    Thread.Sleep(1500);
            //});


            return;

            SoftuniLinkedListFastReverse list = new SoftuniLinkedListFastReverse();

            for (int i = 0; i < 10; i++)
            {
                list.AddLast(new Node(i + 1));
            }
            list.Reverse();
            list.Reverse();
            list.Reverse();
            list.Reverse();

            list.Foreach((node) =>
            {
                Console.WriteLine(node.Value);
            });

            SoftuniLinkedList linkedList = new SoftuniLinkedList();

            Console.WriteLine("Remove empty head: " + linkedList.RemoveHead());

            for (int i = 0; i < 3; i++)
            {
                linkedList.AddHead(new Node(i));
            }
            for (int i = 0; i < 3; i++)
            {
                linkedList.AddLast(new Node(i));
            }

            Console.WriteLine("Remove head: " + linkedList.RemoveHead().Value);

            Console.WriteLine("Remove Tail: " + linkedList.RemoveTail().Value);

            var currentNode = linkedList.Tail;


            Console.WriteLine("Foreach from head:");
            linkedList.ForeachFromHead((node) =>
            {
                Console.WriteLine($"From action: {node.Value}");
            });

            Console.WriteLine("Foreach from Tail:");
            linkedList.ForeachFromTail((node) =>
            {
                Console.WriteLine($"From action: {node.Value}");
            });

            int[] linkedListAsArray = linkedList.ToArray();
        }
Example #4
0
        static void Main(string[] args)
        {
            Node node = new Node(1);
            //node.Next.Next.Next.Next = new Node(5);


            SoftuniLinkedList linkedList = new SoftuniLinkedList();

            Console.WriteLine("Remove empty head: " + linkedList.RemoveHead());

            for (int i = 0; i < 10; i++)
            {
                linkedList.AddHead(new Node(i));
            }

            for (int i = 0; i < 10; i++)
            {
                linkedList.AddLast(new Node(i));
            }
            //linkedList.AddHead(new Node(1));
            //linkedList.AddHead(new Node(2));
            //linkedList.AddHead(new Node(3));
            //linkedList.AddHead(new Node(4));

            Console.WriteLine("Remove head: " + linkedList.RemoveHead().Value);
            Console.WriteLine("Remove head: " + linkedList.RemoveHead().Value);
            Console.WriteLine("Remove head: " + linkedList.RemoveHead().Value);

            Console.WriteLine("Remove tail: " + linkedList.RemoveTail().Value);
            Console.WriteLine("Remove tail: " + linkedList.RemoveTail().Value);
            Console.WriteLine("Remove tail: " + linkedList.RemoveTail().Value);

            //var currentNode = linkedList.Head;

            var currentNode = linkedList.Tail;

            //first build
            //    Node head = new Node(1);
            //    Node node2 = new Node(2);
            //    Node node3 = new Node(3);
            //    Node node4 = new Node(4);

            //    head.Next = node2;
            //    node2.Next = node3;
            //    node3.Next = node4;

            //    Node currentNode = head;


            //while (currentNode !=null)
            //{
            //    Console.WriteLine(currentNode.Value);
            //    currentNode = currentNode.Next;
            //}


            Console.WriteLine("Foreach from head:");
            linkedList.ForeachFromHead((node) =>
            {
                Console.WriteLine($"From action: {node.Value}");
            });

            Console.WriteLine("Foreach from tail:");
            linkedList.ForeachFromTail((node) =>
            {
                Console.WriteLine($"From action: {node.Value}");
            });


            int[] linkedListAsArray = linkedList.ToArray();
        }