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)); }
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); }
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(); }
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); }
static void Main() { try { GenericList<int> list = new GenericList<int>(5); list.Add(1); list.Add(2); list.Add(1); Console.Write("Add : "); Console.WriteLine(list.ToString()); list.Remove(1); Console.Write("Remove : "); Console.WriteLine(list.ToString()); list.Insert(3, 555); Console.Write("Insert : "); Console.WriteLine(list.ToString()); Console.Write("Clear : "); list.ClearList(); Console.WriteLine(list.ToString()); Console.WriteLine("Searching element by its value"); list.Add(1); list.Add(2); list.Add(1); list.Add(2); list.Insert(2, 3); Console.WriteLine(list.ToString()); int indexOfElement = list.FindElement(1, 1); Console.WriteLine(indexOfElement); } catch (ArgumentOutOfRangeException exp) { Console.WriteLine("Error!"); Console.WriteLine(exp); } }
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(); }
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); }
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); }
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() { // Craeting list of strings GenericList<int> list = new GenericList<int>(); // Adding elements in the list list.Add(1); list.Add(2); list.Add(3); list.Add(4); // Iterate through the elements Console.WriteLine("Elements before removing the element at index:{0}", 0); //for (int i = 0; i < list.Count; i++) //{ // Console.WriteLine(list[i]); //} Console.WriteLine(list); // Remove element at position list.RemoveAt(0); // Iterate through elements Console.WriteLine("\nElements after removing the element at index:{0}", 0); //for (int i = 0; i < list.Count; i++) //{ // Console.WriteLine(list[i]); //} Console.WriteLine(list); // Retrieve the min element in the list Console.Write("\nMin element in the list: "); Console.WriteLine(GenericList<int>.Min<int>(list)); // Retrieve the max element in the list Console.Write("\nMax element in the list: "); Console.WriteLine(GenericList<int>.Max<int>(list)); // Clearing the list list.ClearList(); }
static void Main() { GenericList<int> testList = new GenericList<int>(); for (int i = 5; i <= 20; i++) { testList.Add(i); //Testing method Add } for (int i = 0; i < testList.Count - 1; i++) { Console.Write(testList[i]); } Console.WriteLine(); Console.Write("Enter search element of GenericList = "); int searchTofIndex = int.Parse(Console.ReadLine()); var resultIndex = testList.IndexOf(searchTofIndex);// testing method indexOf Console.WriteLine("Search number is {0} = Index [{1}]", searchTofIndex, resultIndex); Console.Write("Enter the number to be inserted = "); int numberOfInsert = int.Parse(Console.ReadLine()); Console.Write("Enter the index to insert = "); int indexUser = int.Parse(Console.ReadLine()); testList.InsertAt(numberOfInsert, indexUser);// testing method InsertAt Console.WriteLine("TestList[{0}] = {1}", indexUser, testList[indexUser]); Console.WriteLine(testList); //ToString, Min and Max Console.WriteLine("Min: {0}", testList.Min()); Console.WriteLine("Max: {0}", testList.Max()); testList.ClearList();//test method clear for (int i = 0; i < testList.Capacity; i++) { Console.Write(testList[i]); } Console.WriteLine(" Test clear"); }
static void Main() { // creating an initial array GenericList<int> testArray = new GenericList<int>(4); Console.WriteLine("The GenericList has {0} elements", testArray.Count); Console.WriteLine("The initial capacity is {0}\n", testArray.Capacity); // adding elemnts for (int i = 1; i < 5; i++) { testArray.Add(i * 5); } Console.WriteLine("Now in the GenericList you have {0} elements ", testArray.Count); Console.WriteLine("The object at position 1 is {0}\n", testArray[1]); // test To.String() method Console.WriteLine("ToString {0}\n", testArray); // test InsertAt method and FindElementIndex method var insertInt = 30; testArray.InsertAt(1, insertInt); Console.WriteLine("Capacity after AutoGrow is {0}", testArray.Capacity); Console.WriteLine("You can find {0} at index {1}" , insertInt, testArray.FindElementIndex(insertInt)); Console.WriteLine("ToString {0}\n", testArray); // test RemoveAt method testArray.RemoveAt(1); Console.WriteLine("Now on position 1 is {0} and the count is {1}", testArray[1], testArray.Count); Console.WriteLine("ToString {0}\n", testArray); // test Min and Max Console.WriteLine("The smallest element is {0} and the biggest is {1}\n" , testArray.MinT(), testArray.MaxT()); // test Clear method testArray.ClearList(); Console.WriteLine("After clear there are {0} elements in the array\n", testArray.Count); }
static void Main(string[] args) { var items = new GenericList<int>(5); items.Add(13); items.Add(450); items.Add(-7); items.Add(13); items.Add(66); items.Add(-17); Console.WriteLine("Max element is: "+items.Max()); Console.WriteLine("Min element is: "+ items.Min()); Console.WriteLine(items.ToString()); items.RemoveElement(3); Console.WriteLine(items.ToString()); items.InsertElement(4, 33); Console.WriteLine(items.ToString()); Console.WriteLine("The index of 33 is {0}",items.IndexOf(33)); items.ClearList(); items.Add(5); Console.WriteLine(items.ToString()); }
static void Main(string[] args) { GenericList<int> intList = new GenericList<int>(); Console.WriteLine(intList); intList.AddElement(1); intList.AddElement(2); intList.AddElement(3); intList.AddElement(12); Console.WriteLine("number of elements in intList: {0}", intList.Count); intList.InsertElement(21, 2); Console.WriteLine(intList); intList.RemoveElement(2); Console.WriteLine(intList); Console.WriteLine(intList[2]); intList.InsertElement(0, 0); intList.AddElement(33); Console.WriteLine(intList); Console.WriteLine(intList.Min()); Console.WriteLine(intList.Max()); intList.ClearList(); Console.WriteLine(intList); Console.WriteLine("number of elements in intList: {0}", intList.Count); }
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); }
static void Main() { // Define list GenericList<int> testList = new GenericList<int>(1); //Test method AddElement and auto grow functionality testList.AddElement(1); testList.AddElement(2); testList.AddElement(3); testList.AddElement(4); Console.WriteLine(testList); // Test method ReadElement Console.WriteLine("Element at position 2 is: {0}", testList.ReadElement(2)); //Test method RemoveElement testList.RemoveElement(1); Console.WriteLine("After removing an element: {0}", testList); //Test method InsertElement testList.InsertElement(2, 111); Console.WriteLine("After inserting an element: {0}", testList); //Test method FindElemenetByValue Console.WriteLine("The element is at position: {0}", testList.FindElemenetByValue(111)); // Test method Min<T> Console.WriteLine("Element with minimum value is: {0}",testList.Min()); // Test method Max<T> Console.WriteLine("Element with maximum value is: {0}", testList.Max()); //Test method ClearList testList.ClearList(); Console.WriteLine("After clearing the list: {0}", testList); }
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()}"); }
static void Main() { Console.WriteLine("Hello! This program tests the functionality of the GenericList project. It will run a few tests to determine if the code has been written correctly. Enjoy!"); Console.WriteLine(); Console.WriteLine("Creating a new generic list of type GenericList<int> and printing it on the console (empty list)"); GenericList<int> list = new GenericList<int>(); Console.WriteLine(list.ToString()); Console.WriteLine(); List<int> testList = new List<int>(); testList.Add(3); // Testing "add" method Console.WriteLine("Adding 4 elements to the list and printing list after each addition:"); list.AddElement(5); Console.WriteLine(list.ToString()); list.AddElement(89); Console.WriteLine(list.ToString()); list.AddElement(-15); Console.WriteLine(list.ToString()); list.AddElement(7); Console.WriteLine(list.ToString()); Console.WriteLine(); // Testing "remove" method Console.WriteLine("Removing elements at positions 2, 2 and 0 consecutively and printing list after each removal:"); list.RemoveElement(2); Console.WriteLine(list.ToString()); list.RemoveElement(2); Console.WriteLine(list.ToString()); list.RemoveElement(0); Console.WriteLine(list.ToString()); Console.WriteLine("Press any key to continue testing..."); Console.ReadKey(); Console.WriteLine(); Console.WriteLine("Adding a new element and prinitng the list:"); list.AddElement(33); Console.WriteLine(list.ToString()); Console.WriteLine(); // Testing "insert" method Console.WriteLine("Inserting '3' at position 1:"); list.InsertElement(1, 3); Console.WriteLine(list.ToString()); Console.WriteLine("Inserting '-4' at position 0:"); list.InsertElement(0, -4); Console.WriteLine(list.ToString()); Console.WriteLine("Inserting '-16' at position 3:"); list.InsertElement(3, -16); Console.WriteLine(list.ToString()); Console.WriteLine(); // Testing class by doing larger amount of operations Console.WriteLine("Adding 50 elements to the list and printing it:"); for (int i = 0; i <= 50; i++) { list.AddElement(i); } Console.WriteLine(list.ToString()); Console.WriteLine(); Console.WriteLine("Removing 25 elements from the list and printing it:"); for (int i = 0; i <= 25; i++) { list.RemoveElement(i); } Console.WriteLine(list.ToString()); Console.WriteLine(); Console.WriteLine("Inserting 15 elements in the list and printing it:"); for (int i = 0; i <= 15; i++) { list.InsertElement(i, i + 3); } Console.WriteLine(list.ToString()); Console.WriteLine(); // Testing "search" method Console.WriteLine("Trying to find element with value 15:"); Console.WriteLine("The element has index [{0}]", list.FindElement(15)); Console.WriteLine(); // Testing "min" and "max" methods Console.WriteLine("Finding the value of the smallest and the biggest elements in the list:"); Console.WriteLine("The smallest element is {0}", list.Min<int>()); Console.WriteLine("The biggest element is {0}", list.Max<int>()); Console.WriteLine(); // Testing "clear" method Console.WriteLine("Clearing the list and printing it on the console:"); list.ClearList(); Console.WriteLine(list.ToString()); // Saying good bye! Console.WriteLine("The test of the GenericList project has been completed successfully! Have a nice day!"); }
static void Main(string[] args) { Console.WriteLine("*********"); Console.WriteLine("POINT 3D:"); Console.WriteLine("*********"); Point3D testPoint1 = new Point3D(5, 6, 7); Point3D testPoint2 = new Point3D(6, 7, 9); Console.WriteLine("Point1: {0}", testPoint1); Console.WriteLine("Point2: {0}", testPoint2); Console.WriteLine("Distance: {0}", Distance3D.Distance(testPoint1, testPoint2)); Console.WriteLine(); Console.WriteLine("**************"); Console.WriteLine("GENERIC CLASS:"); Console.WriteLine("**************"); GenericList<int> testList = new GenericList<int>(2); testList.AddElement(1); testList.AddElement(2); testList.AddElement(3); testList.AddElement(4); testList.AddElement(5); testList.InsertElementAtGivenPosition(6, 1); testList.RemoveElementByIndex(0); Console.WriteLine(testList); Console.WriteLine("Position of 4: {0}", testList.FindElementByValue(4)); Console.WriteLine("Max element: {0}", testList.Max()); Console.WriteLine("Min element: {0}", testList.Min()); Console.WriteLine("Count: {0}", testList.Count); Console.WriteLine("Capacity: {0}", testList.Capacity); testList.ClearList(); testList.AddElement(800); Console.WriteLine(testList); Console.WriteLine(); Console.WriteLine("*************"); Console.WriteLine("MATRIX CLASS:"); Console.WriteLine("*************"); Matrix<int> m1 = new Matrix<int>(3, 3); Matrix<int> m2 = new Matrix<int>(3, 3); // Fill with random numbers Random randomGenerator = new Random(); for (int i = 0; i < m1.Rows; i++) { for (int j = 0; j < m1.Columns; j++) { m1[i, j] = randomGenerator.Next(20); m2[i, j] = randomGenerator.Next(20); } } Console.WriteLine("Matrix 1"); Console.WriteLine(m1); Console.WriteLine("Matrix 2"); Console.WriteLine(m2); Console.WriteLine("Matrix 1 + Matrix 2"); Console.WriteLine(m1 + m2); Console.WriteLine("Matrix 1 - Matrix 2"); Console.WriteLine(m1 - m2); Console.WriteLine("Matrix 1 * Matrix 2"); Console.WriteLine(m1 * m2); Console.WriteLine("******************"); Console.WriteLine("VERSION ATTRIBUTE:"); Console.WriteLine("******************"); Type type = typeof(DefiningClasses); object[] allCustomAttributes = type.GetCustomAttributes(false); foreach (VersionAttribute attribute in allCustomAttributes) { Console.WriteLine("Current version is: {0}", attribute.FullVersion); } }