Example #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());
        }
Example #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());
        }
Example #3
0
        public static void Main()
        {
            GenericList <int> list = new GenericList <int>();

            list.Add(1);
            list.Add(2);
            list.Add(3);
            list.Add(4);
            list.Add(5);
            Console.WriteLine("Making a new list:\n " + list);

            Console.WriteLine("Inserting a number 6 at position 2!");
            list.Insert(2, 6);
            Console.WriteLine(list);

            Console.WriteLine("The position of number 3 is {0}!", list.IndexOf(3));

            Console.WriteLine("Remove an element on position 3.");
            list.RemoveAt(3);
            Console.WriteLine(list);

            Console.WriteLine("The MIN element in the list is {0}", list.Min());
            Console.WriteLine("The MAX element in the list is {0}", list.Max());

            list.Clear();

            Console.WriteLine("The list after list.Clear()! \n" + list);

            //Console.WriteLine(list.Min());
        }
        static void Main()
        {
            GenericList <int> list = new GenericList <int>(8);

            //GenericList<char> list = new GenericList<char>(8);

            Console.WriteLine("Initial list capacity: {0}\n", list.Capacity);

            for (int i = 0; i < 10; i++)
            {
                list.Add(i);
                //list.Add((char)('A' + i));
            }
            Console.WriteLine("List with 10 added elements and new capacity = {0}:", list.Capacity);
            Console.WriteLine(list + Environment.NewLine);

            list.InsertAt(4, 20);
            //list.InsertAt(4, 'Z');
            Console.WriteLine("List with an element insserted at position [4]:");
            Console.WriteLine(list + Environment.NewLine);

            list.RemoveAt(0);
            Console.WriteLine("List with an element removed from position [0]:");
            Console.WriteLine(list + Environment.NewLine);

            int max = list.Max();
            int min = list.Min();
            //char max = list.Max();
            //char min = list.Min();
            int indexOfMax = list.IndexOf(max);
            int indexOfMin = list.IndexOf(min);

            Console.WriteLine("Index of max = {0} is: {1}", max, indexOfMax);
            Console.WriteLine("Index of min = {0} is: {1}", min, indexOfMin);
            Console.WriteLine();

            list.Clear();
            Console.WriteLine("Cleared list:");
            Console.WriteLine(list);
        }