private static void SingleLinkedListRemoveItem()
        {
            Console.WriteLine("Method Name : " + "SingleLinkedListRemoveItem");
            CustomLinkedList <int> customLinkedList = new CustomLinkedList <int>();
            LinkedListNode <int>   node1            = new LinkedListNode <int>(1);

            customLinkedList.AddToLast(node1);
            LinkedListNode <int> node2 = new LinkedListNode <int>(2);

            customLinkedList.AddToLast(node2);
            LinkedListNode <int> node3 = new LinkedListNode <int>(3);

            customLinkedList.AddToLast(node3);
            LinkedListNode <int> node4 = new LinkedListNode <int>(4);

            customLinkedList.AddToLast(node4);
            customLinkedList.PrintLinkedList();
            Console.WriteLine("Does 1 removed from the list : " + customLinkedList.Remove(1));
            customLinkedList.PrintLinkedList();
            Console.WriteLine("Does 10 removed from the list : " + customLinkedList.Remove(10));
            customLinkedList.PrintLinkedList();
            Console.WriteLine("Does 3 removed from the list : " + customLinkedList.Remove(3));
            customLinkedList.PrintLinkedList();
            LinkedListNode <int> node5 = new LinkedListNode <int>(5);

            customLinkedList.AddToLast(node5);
            LinkedListNode <int> node6 = new LinkedListNode <int>(6);

            customLinkedList.AddToLast(node6);
            customLinkedList.PrintLinkedList();
            Console.WriteLine("Does 6 removed from the list : " + customLinkedList.Remove(6));
            customLinkedList.PrintLinkedList();
        }
Beispiel #2
0
        public static CustomLinkedList <int> CreateList()
        {
            var list = new CustomLinkedList <int>();

            list.Add(1);
            list.Add(2);
            list.Add(3);
            list.Add(4);
            list.Add(5);
            list.Add(6);
            return(list);
        }
Beispiel #3
0
        public CustomLinkedList <T> Find(Func <T, bool> where)
        {
            var outputList = new CustomLinkedList <T>();
            var current    = First;

            while (current != null)
            {
                if (where.Invoke(current.value))
                {
                    outputList.Add(current.value);
                }
                current = current.Next;
            }

            return(outputList);
        }
        private static void SingleLinkedListRemoveLast()
        {
            Console.WriteLine("Method Name : " + "SingleLinkedListRemoveLast");
            CustomLinkedList <int> customLinkedList = new CustomLinkedList <int>();
            LinkedListNode <int>   node1            = new LinkedListNode <int>(1);

            customLinkedList.AddToLast(node1);
            LinkedListNode <int> node2 = new LinkedListNode <int>(2);

            customLinkedList.AddToLast(node2);
            LinkedListNode <int> node3 = new LinkedListNode <int>(3);

            customLinkedList.AddToLast(node3);
            LinkedListNode <int> node4 = new LinkedListNode <int>(4);

            customLinkedList.AddToLast(node4);
            customLinkedList.PrintLinkedList();
            Console.WriteLine("No of item in he list is  : " + customLinkedList.Count);
            Console.WriteLine("Removing first item from the list");
            customLinkedList.RemoveLast();
            customLinkedList.PrintLinkedList();
            Console.WriteLine("No of item in he list is  : " + customLinkedList.Count);

            customLinkedList.RemoveLast();
            customLinkedList.PrintLinkedList();
            Console.WriteLine("No of item in he list is  : " + customLinkedList.Count);


            customLinkedList.RemoveLast();
            customLinkedList.PrintLinkedList();
            Console.WriteLine("No of item in he list is  : " + customLinkedList.Count);


            customLinkedList.RemoveLast();
            customLinkedList.PrintLinkedList();
            Console.WriteLine("No of item in he list is  : " + customLinkedList.Count);


            customLinkedList.RemoveLast();
            customLinkedList.PrintLinkedList();
            Console.WriteLine("No of item in he list is  : " + customLinkedList.Count);
        }
        private static void SingleLinkedListContains()
        {
            Console.WriteLine("Method Name : " + "SingleLinkedListContains");
            CustomLinkedList <int> customLinkedList = new CustomLinkedList <int>();
            LinkedListNode <int>   node1            = new LinkedListNode <int>(1);

            customLinkedList.AddToLast(node1);
            LinkedListNode <int> node2 = new LinkedListNode <int>(2);

            customLinkedList.AddToLast(node2);
            LinkedListNode <int> node3 = new LinkedListNode <int>(3);

            customLinkedList.AddToLast(node3);
            LinkedListNode <int> node4 = new LinkedListNode <int>(4);

            customLinkedList.AddToLast(node4);
            customLinkedList.PrintLinkedList();
            Console.WriteLine("Does 1 exist in the list : " + customLinkedList.Contains(1));
            Console.WriteLine("Does 10 exist in the list : " + customLinkedList.Contains(10));
        }
        private static void SingleLinkedListAddToLast()
        {
            Console.WriteLine("Method Name : " + "SingleLinkedListAddToLast");
            CustomLinkedList <int> customLinkedList = new CustomLinkedList <int>();
            LinkedListNode <int>   node1            = new LinkedListNode <int>(1);

            Console.WriteLine("Entering the first node and printing");
            customLinkedList.AddToLast(node1);
            customLinkedList.PrintLinkedList();
            Console.WriteLine("Entering multiple Nodes  and printing");
            LinkedListNode <int> node2 = new LinkedListNode <int>(2);

            customLinkedList.AddToLast(node2);
            LinkedListNode <int> node3 = new LinkedListNode <int>(3);

            customLinkedList.AddToLast(node3);
            LinkedListNode <int> node4 = new LinkedListNode <int>(4);

            customLinkedList.AddToLast(node4);
            customLinkedList.PrintLinkedList();
            Console.WriteLine("No of item in he list is  : " + customLinkedList.Count);
        }