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());
        }
Esempio n. 2
0
        static void Main()
        {
            var myList = new GenericList <int>(4);

            myList.Add(54);
            myList.Add(23);
            Console.WriteLine(myList[0]);
            myList.RemoveByIndex(0);
            myList.Print();
            myList.InsertItem(0, 22);
            myList.Print();
            Console.WriteLine(myList.IndexOf(22));
            myList.Add(3);
            myList.Add(33);
            myList.Add(321);
            Console.WriteLine(myList);

            Console.WriteLine(myList.Min());

            myList.Clear();
            Console.WriteLine(myList);

            Console.WriteLine("==== new test");


            var newlist = new GenericList <int>(8);

            newlist.Add(-43);
            newlist.Add(-1);
            newlist.Add(-23);
            newlist.Print();
            Console.WriteLine(newlist.Min());
            Console.WriteLine(newlist.Max());
        }
Esempio n. 3
0
        public static void Main()
        {
            var list = new GenericList <int>(3);

            list.Add(-5);
            list.Add(10);
            list.Add(15);
            list.InsertAtGivenPosition(3, 20);
            list.RemoveByIndex(3);
            // list.Clear();

            Console.WriteLine(list);
            Console.WriteLine("First index: " + list[1]);
            Console.WriteLine("Min: " + list.Min());
            Console.WriteLine("Max: " + list.Max());
        }