Esempio n. 1
0
        static void Main()
        {
            var myList = new GenericList <int>(5);

            myList.Add(5);
            myList.Add(8);
            myList.Add(123);
            myList.Add(4);
            myList.Add(19);
            Console.WriteLine(myList);    //Problem 5 -- adding elements

            Console.WriteLine(myList[1]); //Problem 5 -- accessing elements by index

            myList.RemoveByIndex(2);
            Console.WriteLine(myList);    //Problem 5 -- removing elements by index

            myList.InsertAtIndex(2, 234); //Problem 5 -- inserting elements by index
            Console.WriteLine(myList);

            myList.InsertAtIndex(1, 567);//Problem 6 -- implementing Auto grow when needed
            Console.WriteLine(myList);
            myList.InsertAtIndex(3, -89);
            Console.WriteLine(myList);

            Console.WriteLine(myList.IndexOf(8)); //Problem 5 -- finding by value (return index)
            Console.WriteLine(myList.IndexOf(6)); // when element not found returns -1

            Console.WriteLine(myList.ToString()); //Problem 5 ToString() override

            Console.WriteLine(myList.Min());      //Problem 7 Min and Max
            Console.WriteLine(myList.Max());

            myList.Clear();//Problem 5 -- Clear the list
            Console.WriteLine(myList.ToString());
        }
        public static void Main()
        {
            /// Test the generic list.

            GenericList <int> testList = new GenericList <int>(8);

            testList[0] = 0;
            testList[1] = 1;
            testList[2] = 2;
            testList[3] = 3;
            testList.AddItem(4);
            testList.AddItem(5);
            testList.AddItem(6);
            testList.AddItem(7);

            Console.WriteLine("The element at 7th position is: {0}\n", testList[7]);

            testList.RemoveAtIndex(2);

            Console.WriteLine("The collection without the removed element at index 2 is:");
            Console.WriteLine(testList.ToString());

            testList.InsertAtIndex(2, 2);

            Console.WriteLine("The collection with the inserted element 2 at index 2 is:");
            Console.WriteLine(testList.ToString());

            int indexOfElement = testList.FindElement(7);

            Console.WriteLine("\nThe index of element 7 is: {0}\n", indexOfElement);

            int min = testList.Min();

            Console.WriteLine("The minimal element in the collection is: {0}\n", min);

            int max = testList.Max();

            Console.WriteLine("The maximal element in the collection is: {0}\n", max);

            testList.ClearList();
            Console.WriteLine("The cleared collection is: [{0}]\n", testList.ToString());
        }