Esempio n. 1
0
 public void AddingElements()
 {
     GenericList<string> generic = new GenericList<string>(2);
     generic.AddElement("Pesho");
     generic.AddElement("Gosho");
     Assert.AreEqual("[Pesho, Gosho]", generic.ToString());
 }
Esempio n. 2
0
        static void Main(string[] args)
        {
            GenericList<int> list = new GenericList<int>(6);

            list.AddElement(1);
            list.AddElement(2);
            list.AddElement(3);
            list.AddElement(4);
 

            //list.InsertElement(0, 9);
            list.InsertElement(0, 9);
            list.InsertElement(0, 9);
            list.InsertElement(0, 9);

            //Console.WriteLine(list.Contains(4));
            //Console.WriteLine(list.FindElement(9));
            //list.RemoveElement(6);

            var type = typeof (GenericList<>);
            var genericListAttributeVersion = type.GetCustomAttribute(typeof(Version), false);
            var attributeVersion = (Version)genericListAttributeVersion;

            Console.WriteLine("Current version is: {0}.{1}", attributeVersion.Major, attributeVersion.Minor);
        }
Esempio n. 3
0
        public static void Main()
        {
            var list = new GenericList<int>();

            var attributes = typeof(GenericList<>).GetCustomAttributes(typeof(VersionAttribute), false);
            Console.WriteLine("Version: {0}", ((VersionAttribute)attributes[0]).Version + Environment.NewLine);

            list.AddElement(3);
            list.AddElement(5);
            list.AddElement(12);
            Console.WriteLine("Add elements: {0}", list + Environment.NewLine);

            Console.WriteLine("Get element at index [0] \r\n{0}",
                list[0] + Environment.NewLine);

            list.RemoveElementAtIndex(1);
            Console.WriteLine("Remove element at index [1] \r\n{0}",
                list + Environment.NewLine);

            list.InsertElementAtIndex(2, -3);
            Console.WriteLine("Insert '-3' at index [2] \r\n{0}",
                list + Environment.NewLine);

            Console.WriteLine("Find element '-3' \r\n{0}",
                list.FindElementByValue(-3) + Environment.NewLine);

            Console.WriteLine("STATISTICS \r\nElements count: {0} \r\nMin element: {1} \r\nMax element: {2}",
                list.Count, list.Min(), list.Max() + Environment.NewLine);

            list.ClearList();
            Console.WriteLine("Clear the list \r\nList count: {0}", list.Count);
        }
Esempio n. 4
0
        static void Main()
        {
            GenericList<int> genList = new GenericList<int>();
            Console.WriteLine("Add elements, double capacity when exceeded capacity:");
            genList.AddElement(8);
            genList.AddElement(2);
            Console.WriteLine("{0,-25}List capacity = {1}; Count = {2}", genList, genList.Capacity, genList.Count);
            genList.AddElement(1);
            genList.AddElement(5);
            Console.WriteLine("{0,-25}List capacity = {1}; Count = {2}", genList, genList.Capacity, genList.Count);
            genList.AddElement(9);
            Console.WriteLine("{0,-25}List capacity = {1}; Count = {2}", genList, genList.Capacity, genList.Count);
            Console.WriteLine("Insert element:");
            Console.WriteLine(genList);
            genList.InsertElement(4, 789);
            Console.WriteLine("{0,-25}List capacity = {1}; Count = {2}", genList, genList.Capacity, genList.Count);
            Console.WriteLine("Remove element:");
            genList.RemoveElement(3);
            Console.WriteLine("{0,-25}List capacity = {1}; Count = {2}", genList, genList.Capacity, genList.Count);

            Console.WriteLine("Find min and max elements:");
            Console.WriteLine("\nThe min element in genList is: {0}", genList.Min());
            Console.WriteLine("\nThe max element in genList is: {0}", genList.Max());

            Console.WriteLine("Clear the list:");
            genList.Clear();
            Console.WriteLine("Count = {0}", genList.Count);
            Console.WriteLine("\nThe genList is now cleared.");
        }
        static void Main()
        {
            //GenericList<string> test = new GenericList<string>();
            //test.AddElement("Testing");
            //test.AddElement("string");
            //Console.WriteLine(test.ToString()); //before inserting a new element
            //test.InsertAtIndex(0, "sf");
            //Console.WriteLine(test.ToString());    //after inserting a new element
            //var testAccessByIndex = test.AccessByIndex(1);
            //Console.WriteLine("I am the element at index 1 = {0}", testAccessByIndex);

           GenericList<double> anotherTest = new GenericList<double>();
           anotherTest.AddElement(1);
           anotherTest.AddElement(2);
           anotherTest.AddElement(3);
           anotherTest.AddElement(4);
          
           Console.WriteLine("Numbers = {0}", anotherTest.ToString());
           var minElement = anotherTest.Min();
           Console.WriteLine("MIN element is {0}", minElement);
           var maxElement = anotherTest.Max();
           Console.WriteLine("MAX element is {0}", maxElement);
           Console.WriteLine("Element[1] using indexer = {0}", anotherTest[1]);
           Console.WriteLine("Element AccessByIndex(1) = {0}", anotherTest.AccessByIndex(1));
           anotherTest.RemoveByIndex(1);
           Console.WriteLine("Removed element[1], result = {0}", anotherTest.ToString());
           anotherTest.InsertAtIndex(1, 5);
           Console.WriteLine("Insert 5 at index[1],result = {0}",anotherTest.ToString());
           anotherTest.ClearList();
           Console.WriteLine("Elements ClearList() = {0}", anotherTest.ToString());
           Console.WriteLine("Check if list contains 0: {0}",anotherTest.FindByValue(0));
        }
 static void Main()
 {
     Console.WriteLine("Hello World.");
     Console.WriteLine("Make new List.");
     GenericList<float> newList = new GenericList<float>(20);
     Console.WriteLine("Add some numbers to the List - 5.3, 6.27, 7.55, 8, 9.09");
     newList.AddElement(5.3f);
     newList.AddElement(6.27f);
     newList.AddElement(7.55f);
     newList.AddElement(8f);
     newList.AddElement(9.09f);
     Console.WriteLine("Print Max element: {0}", newList.Max());
     Console.WriteLine("Print Min element: {0}", newList.Min());
     Console.WriteLine("Add 10 in the biggining.");
     newList.InsertElement(0, 10);
     Console.WriteLine("Print Max element again: {0}", newList.Max());
     Console.WriteLine("Print the List.");
     Console.WriteLine(newList);
     Console.WriteLine("Remove the fourth element.");
     newList.RemoveElement(3);
     Console.WriteLine("Print the List.");
     Console.WriteLine(newList);
     Console.WriteLine("Remove the fourth element.");
     newList.RemoveElement(3);
     Console.WriteLine("Print the List.");
     Console.WriteLine(newList);
     Console.WriteLine("Remove the fourth element.");
     newList.RemoveElement(3);
     Console.WriteLine("Print the List.");
     Console.WriteLine(newList);
     Console.WriteLine("Add 15.56 in the end.");
     newList.InsertElement(3, 15.56f);
     Console.WriteLine("Print the List.");
     Console.WriteLine(newList);
 }
Esempio n. 7
0
    public static void Main()
    {
        //testing bellow all of the defined in GenericList
        GenericList<int> listTesting = new GenericList<int>(1);
        listTesting.AddElement(3);
        listTesting.AddElement(2);
        listTesting.AddElement(-100);
        listTesting.AddElement(1);
        listTesting.AddElement(6);

        Console.WriteLine(listTesting);

        listTesting.RemoveElementAtIndex(1);

        Console.WriteLine(listTesting);

        listTesting.InsertElementAtIndex(0, 21);

        Console.WriteLine(listTesting);

        Console.WriteLine(listTesting.FindElementByValue(7));

        Console.WriteLine(listTesting.Max());
        Console.WriteLine(listTesting.Min());

        listTesting.ClearList();

        Console.WriteLine(listTesting);
    }
Esempio n. 8
0
    static void Main()
    {
        GenericList<int> list = new GenericList<int>();

        Console.WriteLine("Adding numbers:");
        list.AddElement(3);
        list.AddElement(5);
        list.AddElement(12);
        Console.WriteLine(list + Environment.NewLine); // Print

        Console.WriteLine("Inserting [-3] at position [2]");
        list.InsertElementAt(2, -3);
        Console.WriteLine(list + Environment.NewLine); // Print

        Console.WriteLine("Removing element at position [1]");
        list.RemoveElementAtIndex(1);
        Console.WriteLine(list + Environment.NewLine);

        Console.WriteLine("Search for number [-3]");
        Console.WriteLine(list.FindElementValue(-3) + Environment.NewLine);

        Console.WriteLine("STATISTICS");
        Console.WriteLine("Elements count: {0}", list.Count);
        Console.WriteLine("Min element: {0}", list.Min());
        Console.WriteLine("Max element: {0}", list.Max());

        list.ClearList();
        Console.WriteLine();
    }
Esempio n. 9
0
        static void Main(string[] args)
        {
            //New integer list
            GenericList <int> integerCheck = new GenericList <int>(5);

            //Add elements in list
            integerCheck.AddElement(5);
            integerCheck.AddElement(8);
            integerCheck.AddElement(6);
            integerCheck.AddElement(9);
            integerCheck.AddElement(11);

            //Print the elements after they were added
            integerCheck.ToString();

            //Min and max in the list:
            int minIntegerElement = integerCheck.Min();
            int maxIntegerElement = integerCheck.Max();

            //Remove element
            integerCheck.RemoveElement(0);
            Console.WriteLine("\nList after removing element:");
            integerCheck.ToString();


            Console.WriteLine("\nThe min element is {0}", minIntegerElement);
            Console.WriteLine("The max integer element is {0}", maxIntegerElement);
            integerCheck.ClearList();
            Console.WriteLine("Integer list after cleared out.");
            integerCheck.ToString();

            Console.ReadKey();
        }
Esempio n. 10
0
 public void AutoGrowTest()
 {
     GenericList<string> generic = new GenericList<string>(2);
     generic.AddElement("Pesho");
     generic.AddElement("Gosho");
     generic.AddElement("Kircho");
     Assert.AreEqual(4, generic.Count);
 }
Esempio n. 11
0
 public void FindElementTest()
 {
     GenericList<string> generic = new GenericList<string>(2);
     generic.AddElement("Pesho");
     generic.AddElement("Gosho");
     generic.AddElement("Kircho");
     int index = generic.FindElement("Kircho");
     Assert.AreEqual(2, index);
 }
Esempio n. 12
0
        static void Main(string[] args)
        {
            Type type = typeof(GenericList<>);
            object[] versionAttribute = type.GetCustomAttributes(typeof(Version), true);
            foreach (Version attribute in versionAttribute)
            {
                Console.WriteLine("Version: " + attribute.Major + "." + attribute.Minor);
            }

            //creating generic list
            GenericList<int> list = new GenericList<int>(1);

            Console.Write("List with 1 element: ");
            list.AddElement(1);
            Console.WriteLine(list);

            Console.Write("List with 2 elements: ");
            list.AddElement(2);
            Console.WriteLine(list);

            Console.Write("Insering the element 0: ");
            list.InsertElement(0, 0);
            Console.WriteLine(list);

            Console.Write("We add element 2 again: ");
            list.AddElement(2);
            Console.WriteLine(list);

            Console.Write("Minimal element: ");
            Console.WriteLine(list.Min());

            Console.Write("Max element: ");
            Console.WriteLine(list.Max());
            Console.WriteLine();

            //creating new generic string list
            GenericList<string> stringList = new GenericList<string>();

            Console.Write("Adding first element \"one\": ");
            stringList.AddElement("one");
            Console.WriteLine(stringList);

            Console.Write("Adding second element \"two\": ");
            stringList.AddElement("two");
            Console.WriteLine(stringList);

            Console.Write("The list contains \"one\" at position: ");
            Console.WriteLine(stringList.Cointains("one"));

            Console.WriteLine("The list contains \"two\" at position: ");
            Console.WriteLine(stringList.Cointains("two"));

            //clearing the generic list
            stringList.ClearList();
            Console.WriteLine(stringList);
        }
Esempio n. 13
0
        public void AccessByIndexException()
        {
            GenericList<string> myList = new GenericList<string>(3);

            myList.AddElement("alpha");
            myList.AddElement("beta");
            myList.AddElement("gama");

            var actual = myList[3];
        }
Esempio n. 14
0
        static void Main(string[] args)
        {
            GenericList<object> processingGenericList = new GenericList<object>();
            object[] list;


            //Testing

            processingGenericList.AddElement(0);
            processingGenericList.AddElement(1);
            processingGenericList.AddElement(2);
            processingGenericList.InsertElement(15,8);
            processingGenericList.AddElement(3);
            processingGenericList.AddElement(4);
            processingGenericList.AddElement(5);
            processingGenericList.AddElement(-1);
            processingGenericList.AddElement(7);
            processingGenericList.AddElement(8);
               
            list = processingGenericList.returnList();
            for (int i = 0; i < list.Length; i++)
            {
               Console.WriteLine(list[i]);
            }

            Console.WriteLine("Min is: " + processingGenericList.Min());
            Console.WriteLine("Max is: " + processingGenericList.Max());
        }
Esempio n. 15
0
        public static void Main()
        {
            GenericList<string> strings = new GenericList<string>(10);

            strings.AddElement("Nikolai");
            strings.AddElement("Mishev");
            Console.WriteLine(strings[0]+ "-" + strings[1]);

            Console.WriteLine(strings.Count.ToString());
            Console.WriteLine(strings.FindElement("Nilai"));
        }
Esempio n. 16
0
 public void AutoGrowTest2()
 {
     //two times autogrow
     GenericList<int> generic = new GenericList<int>(2);
     generic.AddElement(1);
     generic.AddElement(2);
     generic.AddElement(3);
     generic.AddElement(4);
     generic.AddElement(5);
     Assert.AreEqual(8, generic.Count);
 }
Esempio n. 17
0
        public void AddingElementString()
        {
            GenericList<string> myList = new GenericList<string>(3);

            myList.AddElement("alpha");
            myList.AddElement("beta");

            var expected = "alphabeta";
            var actual = "" + myList[0] + myList[1] + myList[2];

            Assert.AreEqual(expected, actual);
        }
        static void Main()
        {
            Path p = new Path();
            p.AddPoint(new Point3D(1, 2, 3));
            p.AddPoint(new Point3D(5, 2, 6));
            p.AddPoint(new Point3D(1, 3, 5));
            p.AddPoint(new Point3D(-5, 2, 3));
            p.AddPoint(new Point3D(-2, -10, 3));

            PathStorage.SavePath(p); //Save path in file savedPaths.txt
            Path final = PathStorage.LoadPath(); //loading from the file savedPaths.txt
            final.PrintPathList(); //printing the loaded path

            ////05, 06, 07->

            GenericList<int> list = new GenericList<int>();
            list.AddElement(10);
            list.AddElement(5);
            list.AddElement(4);
            list.InsertElement(1, 15);
            list.InsertElement(1, 12);
            Console.WriteLine(list.ToString());
            Console.WriteLine();
            list[0] = 5;
            int min = list.Min();
            int max = list.Max();
            Console.WriteLine(min);
            Console.WriteLine(max);
            list.Clear();
            Console.WriteLine(list.ToString());

            /////08, 09, 10 ->

            double[,] first = { { 0, 2, 3, 4.2 }, { 1, 2, 3, 4 }, { 1, 2, 3, 4 }, { 1, 2, 3, 4 } };
            double[,] second = { { 1, 2, 3, 4 }, { 1, 2, 3, 4 }, { 1, 2, 3, 4 }, { 1, 0, 3, 4 } };

            Matrix<double> arrFirst = new Matrix<double>(first);
            Matrix<double> arrSecond = new Matrix<double>(second);

            //checking if contain zero, return true, if not, return false if there is zero
            if (arrFirst)
            {
                Console.WriteLine("There is no zero inside");
            }
            else Console.WriteLine("There is at least one zero inside\n");
            //-----------
            Console.WriteLine("Sum of the two matrices");
            Console.WriteLine(arrFirst + arrSecond);
            Console.WriteLine("Substraction of the two matrices");
            Console.WriteLine(arrFirst - arrSecond);
            Console.WriteLine("Multiplication of the two matrices");
            Console.WriteLine(arrFirst * arrSecond);
        }
Esempio n. 19
0
        public void AccessByValue()
        {
            GenericList<string> myList = new GenericList<string>(3);

            myList.AddElement("alpha");
            myList.AddElement("beta");
            myList.AddElement("gama");

            var expected = 2;
            var actual = myList.GetPosition("gama");

            Assert.AreEqual(expected, actual);
        }
Esempio n. 20
0
        public void AccessByIndex()
        {
            GenericList<string> myList = new GenericList<string>(3);

            myList.AddElement("alpha");
            myList.AddElement("beta");
            myList.AddElement("gama");

            var expected = "beta";
            var actual = myList[1];

            Assert.AreEqual(expected, actual);
        }
Esempio n. 21
0
        public void AddingElementInt()
        {
            GenericList<int> myList = new GenericList<int>(3); // {0,0,0}

            myList.AddElement(2); // {2,0,0}
            myList.AddElement(0); // {2,0,0}
            myList.AddElement(7); // {2,0,7};

            var expected = "207";
            var actual = "" +myList[0] + myList[1] + myList[2];

            Assert.AreEqual(expected, actual);
        }
Esempio n. 22
0
 public void ClearTest()
 {
     GenericList<int> generic = new GenericList<int>(10);
     generic.AddElement(2);
     generic.AddElement(3);
     generic.AddElement(4);
     generic.AddElement(0);
     generic.AddElement(0);
     generic.ClearArray();
     for (int i = 0; i < generic.Length; i++)
     {
         Assert.AreEqual(0, generic[i]);
     }
 }
Esempio n. 23
0
        static void Main()
        {
            GenericList<int> test = new GenericList<int>();
            GenericList<int> test1 = new GenericList<int>(5);

            for (int i = 0; i < 10; i++)
            {
                test.AddElement(i + 1);
                Console.WriteLine("Element {0,5}    Count {1,5}    Capacity {2,5}",test[i],test.Count,test.Capacity);
            }

            Console.WriteLine();
            for (int i = 0; i < test1.Capacity; i++)
            {
                test1.AddElement(i + 10);
                Console.WriteLine("Element {0,5}    Count {1,5}    Capacity {2,5}", test1[i], test1.Count, test1.Capacity);
            }

            Console.WriteLine();
            test.InsertAt(1, 22);
            Console.WriteLine(test);
            Console.WriteLine("New length: {0}",test.Count);
            Console.WriteLine();
            test1.RemoveAt(2);
            Console.WriteLine(test1);
            Console.WriteLine("New length: {0}",test1.Count);

            Console.WriteLine();
            Console.WriteLine("Min: {0}",test.Min());
            Console.WriteLine("Max: {0}",test.Max());
        }
Esempio n. 24
0
 static void Main()
 {
     GenericList<int> list = new GenericList<int>();
     list.AddElement(10);
     list.AddElement(5);
     list.AddElement(4);
     list.InsertElement(1, 15);
     list.InsertElement(1, 12);
     Console.WriteLine(list.ToString());
     Console.WriteLine();
     list[0] = 5;
     int min = list.Min();
     int max = list.Max();
     Console.WriteLine(min);
     Console.WriteLine(max);
     list.Clear();
     Console.WriteLine(list.ToString());
 }
Esempio n. 25
0
 static void Main()
 {
     GenericList<int> intList = new GenericList<int>();
     intList.AddElement(5);
     intList.AddElement(10);
     intList.AddElement(15);
     Console.WriteLine(intList);
     intList.InsertElementAt(1, 20);
     Console.WriteLine(intList);
     intList.RemoveElementAtIndex(2);
     Console.WriteLine(intList);
     intList.AddElement(50);
     intList.AddElement(60);
     Console.WriteLine(intList);
     Console.WriteLine("Elements Count: {0}", intList.Count);
     Console.WriteLine("Min: {0}", intList.Min());
     Console.WriteLine("Max: {0}", intList.Max());
     Console.WriteLine(new String('-', 30));
 }
Esempio n. 26
0
    static void Main()
    {
        GenericList<int> nums = new GenericList<int>(2);
        // Add elements
        nums.AddElement(5);
        nums.AddElement(10);
        nums.AddElement(1);
        nums.AddElement(8);
        Console.WriteLine("List after adding elements: " + nums + "\n");

        // Remove elements
        nums.RemoveElement(1);
        nums.RemoveElement(2);
        Console.WriteLine("List after removing elements: " + nums + "\n");

        // show element at index
        Console.WriteLine("Element at given index: " + nums.ElementAtIndex(0) + "\n");

        // insert elements at index
        nums.InsertElementAtIndex(10, 50);
        Console.WriteLine(nums);
        nums.InsertElementAtIndex(1, 999);
        Console.WriteLine(nums + "\n");

        // find index of given element
        nums.FindIndex(999);
        nums.FindIndex(444);
        Console.WriteLine();

        // check if list contains element
        Console.WriteLine(nums.Contains(999));
        Console.WriteLine(nums.Contains(444));
        Console.WriteLine();

        // find min element
        Console.WriteLine("Min element is: " + GenericList<int>.Min(10, 7) + "\n");
        // find max element
        Console.WriteLine("Max element is: " + GenericList<string>.Max("Albena", "Ruse"));

        // clear list
        nums.ClearList();
        Console.WriteLine(nums);
    }
        static void Main()
        {
            //Create generic list
            GenericList<int> myList = new GenericList<int>(2);

            //Add elemnets
            myList.AddElement(30);
            myList.AddElement(2);
            myList.AddElement(3);

            Console.WriteLine(myList);

            //Access element by index
            Console.Write("The element at index 0 is: ");
            Console.WriteLine(myList.GetElementAtIndex(0));
            Console.WriteLine();

            //Remove element at certain index
            myList.RemoveElementAtIndex(1);
            Console.WriteLine("The element at index 1 has been removed!");
            Console.WriteLine(myList);

            //Insert element at certain index
            myList.InsertElementAtIndex(1, 800);
            Console.WriteLine("The element at index 1 has been inserted!");
            Console.WriteLine(myList);

            //Find index of value 800 and 3000
            Console.Write("The value 800 has index of: ");
            Console.WriteLine(myList.FindElement(800));
            Console.Write("The value 3000 has index of: ");
            Console.WriteLine(myList.FindElement(3000));

            //Min element in list
            Console.WriteLine();
            Console.Write("The min element is:");
            Console.WriteLine(myList.MinElement());

            //Max element in list
            Console.Write("The max element is:");
            Console.WriteLine(myList.MaxElement());
        }
Esempio n. 28
0
 static void Main()
 {
     GenericList<int> testList = new GenericList<int>(4);
     testList.AddElement(10);
     testList.AddElement(15);
     testList.AddElement(50);
     testList.AddElement(30);
     Console.WriteLine("Initial list contents:\n"+testList);
     testList.RemoveAt(1);
     Console.WriteLine("Minimal element: {0} Maximal element: {1}\n",testList.Min(),testList.Max());
     Console.WriteLine("List contents after element at index 1 is removed:\n" + testList);
     testList.InsertAt(20, 1);
     Console.WriteLine("List contents after inserting 20 at index 1:\n" + testList);
     int indexOfElement = testList.FindElement(50);
     Console.WriteLine("Index of element with value equal to 50 ---> " + indexOfElement+"\n");
     Console.WriteLine("Capacity before adding element to overfill internal array:" + testList.Capacity+"\n");
     testList.AddElement(40);
     Console.WriteLine("Capacity after adding element(auto-grow functionality is tested here):" + testList.Capacity + "\n");
     testList.Clear();
     Console.WriteLine("List contents after list is cleared:");
 }
Esempio n. 29
0
    public static void Main()
    {
        GenericList<int> listTesting = new GenericList<int>(1);
        listTesting.AddElement(2);
        listTesting.AddElement(3);
        listTesting.AddElement(4);
        listTesting.AddElement(5);
        listTesting.AddElement(6);
        listTesting.AddElement(-1000);

        Console.WriteLine(listTesting);

        listTesting.RemoveElemAtIndex(4);

        Console.WriteLine(listTesting);

        listTesting.InsertElemAtIndex(0, 123);

        Console.WriteLine(listTesting);

        Console.WriteLine(listTesting.FindElemByValue(123));

        Console.WriteLine(listTesting.Max());
        Console.WriteLine(listTesting.Min());

        listTesting.ClearList();

        Console.WriteLine(listTesting);
    }
Esempio n. 30
0
        static void Main()
        {
            var elements = new GenericList<int>();
            elements.AddElement(1);
            elements.AddElement(2);
            elements.AddElement(4);
            elements.AddElement(3);
            Console.WriteLine("Your elements:");
            elements.ToString();
            Console.WriteLine($"Min:{elements.Min()}");
            Console.WriteLine($"Max:{elements.Max()}");
            Console.WriteLine("Insert 10 at position 0 and remove index 2:");
            elements.InsertAt(0, 10);
            elements.RemoveAt(1);
            elements.ToString();

            Console.WriteLine("Find 3 at position:");
            Console.WriteLine(elements.Find(3));
            Console.WriteLine("Cleared elements:");
            elements.Clear();
            Console.WriteLine(elements.ToString());
        }
        static void Main()
        {
            GenericList<int> a = new GenericList<int>(34);

            //Console.WriteLine(a.Capacity);
            a.AddElement(6);
            a.AddElement(7);
            a.AddElement(8);
            //Console.WriteLine(a.Count);

            //Console.WriteLine(a.GetElement(2));

            a.RemoveElement(2);

            for (int i = 0; i < a.Count; i++)
            {
                Console.WriteLine(a.GetElement(i));
            }

            Console.WriteLine();
            a.InsertElement(24, 5);

            for (int i = 0; i < a.Count; i++)
            {
                Console.WriteLine(a.GetElement(i));
            }
            Console.WriteLine();

            //a.Clear();
            //for (int i = 0; i < a.Count; i++)
            //{
            //    Console.WriteLine(a.GetElement(i));
            //}

            Console.WriteLine();

            Console.WriteLine(a.GetIndexOf(7));
        }
Esempio n. 32
0
        public static void TestGenericList()
        {
            Console.WriteLine("---- Testing Tasks 5,6 ----");
            var list = new GenericList <int>(3);

            list.AddElement(5);
            list.AddElement(10);
            list.AddElement(15);
            list.AddElement(20);
            Console.WriteLine($"list = {list}");
            list.RemoveElementByIndex(1);
            Console.WriteLine($"Eelemnt 1 removed. List = {list}");
            list.AddElement(2);
            Console.WriteLine($"Element 2 added. List = {list}");
            list.InsertElementAtIndex(1, 22);
            Console.WriteLine($"Element 22 added at index 1. List = {list}");
            list.ClearList();
            Console.WriteLine($"List cleared:{list}");

            Console.WriteLine("---- Testing Task 7 ----");
            list.InsertElementAtIndex(0, -5);
            list.InsertElementAtIndex(1, 0);
            list.InsertElementAtIndex(2, 5);
            list.InsertElementAtIndex(3, 10);
            Console.WriteLine($"list = {list}");
            Console.WriteLine($"list Min Value = {list.Min()}");
            Console.WriteLine($"list Max Value = {list.Max()}");
            var stringList = new GenericList <string>(3);

            stringList.AddElement("a");
            stringList.AddElement("cc");
            stringList.AddElement("bbb");
            Console.WriteLine($"stringList = {stringList}");
            Console.WriteLine($"stringList Min value = {stringList.Min()}");
            Console.WriteLine($"stringList Max value = {stringList.Max()}");
        }
Esempio n. 33
0
    static void Main()
    {
        GenericList <int> a = new GenericList <int>(4);

        Console.WriteLine(a.ToString());

        GenericList <decimal> exampleB = new GenericList <decimal>(4);

        exampleB.AddElement(3.4231231m);
        exampleB.AddElement(238.47326478234m);
        exampleB.AddElement(-18.346287346287m);
        exampleB.AddElement(3.147432684m);
        exampleB.AddElement(2.3567894m);
        exampleB.AddElement(-2.2m);

        Console.WriteLine(exampleB[3]);

        Console.WriteLine("Max = {0}", exampleB.Max <decimal>());
        Console.WriteLine("Min = {0}", exampleB.Min <decimal>());

        Console.WriteLine(exampleB.ToString());
    }
Esempio n. 34
0
    public static void Main()
    {
        GenericList <int> list = new GenericList <int>();

        // display version
        Type type = typeof(GenericList <>);

        object[] allAttributes = type.GetCustomAttributes(typeof(VersionAttribute), false);
        Console.WriteLine("Class's Version {0} \n", allAttributes[0]);

        list.AddElement(4);
        list.AddElement(324235);
        list.AddElement(56);
        list.AddElement(1000);
        list.AddElement(12345);

        list.InsertElement(2, 100);

        list.RemoveElement(2);

        Console.WriteLine(list[2]);

        Console.WriteLine(list.ReturnIndex(12345));

        Console.WriteLine(list.IsContains(10));

        Console.WriteLine(list.MaxValue <int>());
        Console.WriteLine(list.MinValue <int>());

        Console.WriteLine(list);

        list.ClearList();

        // list.MaxValue<int>(); // this throws an exception
        list.AddElement(234);
        Console.WriteLine(list);
    }
Esempio n. 35
0
        public void TestMethod2()
        {
            //We create a Matrix<int> array of 1 element
            Matrix <int> [] matrixArr = new Matrix <int> [1] {
                new Matrix <int>(new int [2, 2] {
                    { 1, 1 }, { 2, 2 }
                })
            };

            //The created GenericList is with capacity - 2 elements
            GenericList <Matrix <int> > matrixGenericList = new GenericList <Matrix <int> >(matrixArr);

            //We add new element to the Generic list and it is full
            matrixGenericList.AddElement(new Matrix <int>(new int[2, 2] {
                { 3, 3 }, { 4, 4 }
            }));

            //We add one more new element and the Generic list should double its capacity
            matrixGenericList.AddElement(new Matrix <int>(new int[2, 2] {
                { 5, 5 }, { 6, 6 }
            }));

            //We remove the middle element
            matrixGenericList.RemoveElement(1);

            //We insert one new element in the middle
            matrixGenericList.InsertElement(1, new Matrix <int>(new int[2, 2] {
                { 7, 7 }, { 8, 8 }
            }));

            //Find the index of the matrix { { 7, 7 }, { 8, 8 } }
            int indexSearch;

            if (matrixGenericList.FindElementIndex(new Matrix <int>(new int[2, 2] {
                { 7, 7 }, { 8, 8 }
            }), out indexSearch))
            {
                Assert.AreEqual(1, indexSearch);
            }

            //Find min matrix
            Matrix <int> minMatrix = matrixGenericList.Min();

            //Find max matrix
            Matrix <int> maxMatrix = matrixGenericList.Max();

            //Convert the list to string
            string genericListToString = matrixGenericList.ToString();


            //Check matrix not Zero and use GenericList index
            bool zeroMatrix = matrixGenericList[0] ? true : false;

            Assert.AreEqual(true, zeroMatrix);

            //Check Zero matrix
            zeroMatrix = new Matrix <int>(new int[1, 1] {
                { 0 }
            }) ? true : false;
            Assert.AreEqual(false, zeroMatrix);

            //Sum 2 matrixes
            matrixGenericList[0] = matrixGenericList[0] + matrixGenericList[1];

            //Subtract 2 matrixes
            matrixGenericList[0] = matrixGenericList[0] - matrixGenericList[1];

            //Multiply 2 matrixes
            matrixGenericList[0] = matrixGenericList[0] * matrixGenericList[1];
        }
Esempio n. 36
0
        public static void Main(string[] args)
        {
            Console.WriteLine("**********TASK1**********\n");

            Console.WriteLine("-----POINT COORDINATES-----");
            Point3D p = new Point3D(3, 5, 6);

            Console.WriteLine(p.ToString());

            Console.WriteLine("\n**********TASK2**********\n");

            Console.WriteLine("-----ZERO POINT COORDINATES-----");
            Point3D zeroPoint = new Point3D();

            Console.WriteLine(zeroPoint.ToString());

            Console.WriteLine("\n**********TASK3**********\n");

            Console.WriteLine("-----POINT ONE COORDINATES-----");

            Point3D p1 = new Point3D(8, 6, 4);

            Console.WriteLine(p1.ToString());

            Console.WriteLine("-----POINT TWO COORDINATES-----");

            Point3D p2 = new Point3D(2, 3.4, 0);

            Console.WriteLine(p2.ToString());

            Console.WriteLine("-----THE DISTANCE BETWEEN TWO POINTS-----");

            var distance = CalculateDistanceBetween2Points.DistansBetweenTowPoints(p1, p2);

            Console.WriteLine("{0}", distance);

            Console.WriteLine("\n**********TASK4**********\n");

            Path path = new Path();

            path.AddPoint(new Point3D(1, 2, 3));
            path.AddPoint(new Point3D(6, 8, 6));
            path.AddPoint(new Point3D(2, 5, 7));
            path.AddPoint(new Point3D(1, 2, 0));

            Console.WriteLine("-----SAVING POINTS COORDINATES TO FILE-----");

            PathStorage.SavePath(path, "file");
            Path loadedPath = PathStorage.LoadPath("file");

            Console.WriteLine("-----LOADING POINTS COORDINATES FROM FILE-----");

            foreach (var item in loadedPath.PointList)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("\n**********TASK5**********\n");

            GenericList <int> genericList = new GenericList <int>(5);

            genericList.AddElement(5);
            genericList.AddElement(11);

            Console.WriteLine("---ADDING ELEMENT TO THE LIST---");
            Console.WriteLine("{0}", genericList[0]);
            Console.WriteLine("---ADDING ELEMENT TO THE LIST---");
            Console.WriteLine("{0}", genericList[1]);
            Console.WriteLine("{0}", genericList.ToString());

            Console.WriteLine("---REMOVING ELEMENT FROM THE LIST---");
            Console.WriteLine("Element value: {0}\nRemoved from position: {1}", genericList[0], 0);

            genericList.RemoveElementByIndex(0);
            Console.WriteLine("{0}", genericList.ToString());

            genericList.InsertElementAtPosition(0, 100);
            Console.WriteLine("Element {0} is inserted at position {1}", genericList[0], 0);
            Console.WriteLine("{0}", genericList.ToString());

            genericList.AddElement(5);
            genericList.AddElement(1);
            genericList.AddElement(2);
            genericList.AddElement(3);

            Console.WriteLine("Element's index is: {0}", genericList.FindElementByItsValue(100));
            Console.WriteLine("Element value is: {0}\n", genericList[0]);
            Console.WriteLine("Element's index is: {0}", genericList.FindElementByItsValue(11));
            Console.WriteLine("Element value is: {0}\n", genericList[1]);
            Console.WriteLine("{0}", genericList.ToString());

            genericList.ClearAllElements();
            Console.WriteLine("{0}", genericList.ToString());

            Console.WriteLine("**********TASK6**********\n");

            Console.WriteLine("---THE LIST IS GROWING AUTOMATICALY---");

            Console.WriteLine("\n**********TASK7**********\n");

            genericList.AddElement(5);
            genericList.AddElement(1);
            genericList.AddElement(2);
            genericList.AddElement(3);
            genericList.AddElement(231);

            Console.WriteLine("{0}", genericList.ToString());
            Console.WriteLine("{0}", genericList.Min());
            Console.WriteLine("{0}", genericList.Max());

            Console.WriteLine("\n**********TASK8**********\n");

            Matrix <int> matrix1 = new Matrix <int>(2, 2);

            matrix1[0, 0] = 5;
            matrix1[0, 1] = 2;
            matrix1[1, 0] = 3;
            matrix1[1, 1] = 15;

            Console.WriteLine("-----MATRIX 1-----");
            Console.WriteLine(matrix1.ToString());

            Matrix <int> matrix2 = new Matrix <int>(2, 2);

            matrix2[0, 0] = 6;
            matrix2[0, 1] = 7;
            matrix2[1, 0] = -5;
            matrix2[1, 1] = 0;

            Console.WriteLine("-----MATRIX 2-----");
            Console.WriteLine(matrix2.ToString());

            Console.WriteLine("\n**********TASK9**********\n");

            Console.WriteLine("-----ACCESSING ELEMENTS OF MATRIX 1-----");
            Console.WriteLine(matrix1[0, 0] + ", " + matrix1[0, 1] + ", " + matrix1[1, 0] + ", " + matrix1[1, 1]);

            Console.WriteLine("-----ACCESSING ELEMENTS OF MATRIX 2-----");
            Console.WriteLine(matrix2[0, 0] + ", " + matrix2[0, 1] + ", " + matrix2[1, 0] + ", " + matrix2[1, 1]);

            Console.WriteLine("\n**********TASK10**********\n");

            Console.WriteLine("-----MATRIX 1 + MATRIX 2-----");
            Console.WriteLine(matrix1 + matrix2);

            Console.WriteLine("-----MATRIX 1 - MATRIX 2-----");
            Console.WriteLine(matrix1 - matrix2);

            Console.WriteLine("-----MATRIX 1 * MATRIX 2-----");
            Console.WriteLine(matrix1 * matrix2);

            Console.WriteLine("-----CHECKING FOR TRUE/FALSE IN MATRIX 1-----");
            Console.WriteLine("(If there is zero in the matrix the result is False)");

            if (matrix1)
            {
                Console.WriteLine("True");
            }
            else
            {
                Console.WriteLine("False");
            }

            Console.WriteLine("-----CHECKING FOR TRUE/FALSE IN MATRIX 2-----");
            Console.WriteLine("(If there is zero in the matrix the result is False)");

            if (matrix2)
            {
                Console.WriteLine("True");
            }
            else
            {
                Console.WriteLine("False");
            }

            Console.WriteLine("\n**********TASK11**********\n");

            var type       = typeof(Demo);
            var attributes = type.GetCustomAttributes(false);

            foreach (Version_Attribute atr in attributes)
            {
                Console.WriteLine("Version: {0}", atr.ToString());
            }
        }