Exemplo n.º 1
0
        public static void ShowLinkedListTemplate()
        {
            var list = new Tasks.LinkedList <string>();
            CollectionChangeEventHandler showInfo = (sender, e) =>
            {
                Console.WriteLine($"First = {list.First}, Next = {list.Next}");
                ShowAction($"{e.Action}: {e.Element}", list);
            };

            list.InsertEvent += showInfo;
            list.RemoveEvent += showInfo;
            list.ClearEvent  += showInfo;
            list.AddLast("hello");
            list.AddLast(", what");
            var name = "Any, ";

            list.AddFirst(name);
            list.AddLast(" are");
            var str = " you";

            list.AddLast(str);
            list.AddLast(" doing?");
            list.Replace(str, "they");
            Console.WriteLine($"First = {list.First}, Next = {list.Next}");
            ShowAction($"Replace: {str}", list);
            list.Remove(name);
            list.Clear();
            list.AddFirst("one");
            list.AddFirst("two");
            list.AddLast("3");
            var otherList = new Tasks.LinkedList <string>();

            otherList.InsertEvent += (sender, e) =>
            {
                Console.WriteLine($"First = {otherList.First}, Next = {otherList.Next}");
                ShowAction($"{e.Action}: {e.Element}", otherList);
            };
            otherList.AddLast("sdfgtyhuiop");
            list.CopyTo(otherList);
            ShowAction($"Copy: ", otherList);
        }
Exemplo n.º 2
0
        public static void ShowLinkedList()
        {
            var list = new LinkedList();
            CollectionChangeEventHandler showInfo = (sender, e) =>
            {
                Console.WriteLine($"First = {list.First}, Next = {list.Next}");
                ShowAction($"{e.Action}: {e.Element}", list);
            };

            list.InsertEvent += showInfo;
            list.RemoveEvent += showInfo;
            list.ClearEvent  += showInfo;
            list.AddLast("hello");
            list.AddLast(123);
            var name = "Any, ";

            list.AddFirst(name);
            list.AddLast(new Stack());
            var str = " you";

            list.AddLast(str);
            list.AddLast(-12.343);
            list.Replace(str, new ObjectComparer());
            Console.WriteLine($"First = {list.First}, Next = {list.Next}");
            ShowAction($"Replace: {str}", list);
            list.Remove(name);
            list.Clear();
            list.AddFirst("one");
            list.AddFirst(2.0);
            list.AddLast(3);
            var otherList = new Tasks.LinkedList();

            otherList.InsertEvent += (sender, e) =>
            {
                Console.WriteLine($"First = {otherList.First}, Next = {otherList.Next}");
                ShowAction($"{e.Action}: {e.Element}", otherList);
            };
            otherList.AddLast("sdfgtyhuiop");
            list.CopyTo(otherList);
            ShowAction("Copy: ", otherList);
        }