Beispiel #1
0
        public CustomLinkedList <T> ReverseList()
        {
            CustomLinkedList <T> reversedList = new CustomLinkedList <T>();

            for (int i = Count - 1; i >= 0; i--)
            {
                reversedList.AddToEndOfList(new LinkedListNode <T>()
                {
                    Value = GetAtIndex(i)
                });
            }

            return(reversedList);
        }
        public static void CustomLinkedListTest()
        {
            CustomLinkedList <int> myList = new CustomLinkedList <int>();

            myList.AddToEndOfList(new LinkedListNode <int>()
            {
                Value = 3
            });
            myList.AddToEndOfList(new LinkedListNode <int>()
            {
                Value = 54
            });
            myList.AddToEndOfList(new LinkedListNode <int>()
            {
                Value = 999
            });
            myList.AddToEndOfList(new LinkedListNode <int>()
            {
                Value = 11
            });
            myList.AddToEndOfList(new LinkedListNode <int>()
            {
                Value = 32
            });
            myList.AddToBegginingOfList(new LinkedListNode <int>()
            {
                Value = 6
            });
            myList.PrintAll();

            Console.WriteLine("**Reversing List**");
            CustomLinkedList <int> reversedList = myList.ReverseList();

            reversedList.PrintAll();

            Console.WriteLine("Printing Index 2");
            int myIndex = myList.GetAtIndex(2);

            Console.WriteLine(myIndex.ToString());
        }