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() { 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()); }
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()); }
static void Main() { // Problem 5. Generic class var list = new GenericList <int>(8); list.Add(5); list.Add(22); list.Add(31); // list.Remove(1); // list.Insert(1, 333); Console.WriteLine(list); Console.WriteLine(); // Problem 6. Auto-grow list.Add(5); list.Add(22); list.Add(31); list.Add(-100); Console.WriteLine(list); Console.WriteLine(); // Problem 7. Min and Max Console.WriteLine(list.Max()); Console.WriteLine(list.Min()); }
static void Main(string[] args) { var numbers = new GenericList <int>(); for (int i = 2; i <= 4; i++) { numbers.Add(i); } //numbers.Print(); //for (int i = 5; i <= 7; i++) //{ // numbers.RemoveFirst(i); //} //numbers.Print(); //Console.WriteLine(numbers[0]); //numbers[1] = 33; //numbers[3] = 99; //numbers[5] = -1; //numbers.Print(); //numbers.RemoveAt(1); //numbers.RemoveAt(1); //numbers.Print(); //numbers.InsertAt(33, 1); //numbers.Print(); //numbers.Clear(); //numbers.Print(); //numbers--; //--numbers; //numbers.Print(); if (numbers) { Console.WriteLine(numbers[0] + " " + numbers[numbers.Count - 1]); } var minV = numbers.Min <Int32>(); Console.WriteLine(minV); var maxV = numbers.Max <Int32>(); Console.WriteLine(maxV); //Console.WriteLine(numbers[10]); }
public static void Main() { var myListInt = new GenericList <int>(); myListInt.Add(2); myListInt.Add(5); myListInt.Add(16); myListInt.Add(78); myListInt.Add(52); myListInt.Add(9); Console.WriteLine("Min element in list is: {0}", myListInt.Min()); Console.WriteLine(); Console.WriteLine("Max element in list is: {0}", myListInt.Max()); Console.WriteLine(); var myListString = new GenericList <string>(); myListString.Add("Ivan"); myListString.Add("Petar"); myListString.Add("Georgi"); myListString.Add("Todor"); myListString.Add("Stoyan"); Console.WriteLine(myListString[4]); Console.WriteLine(); Console.WriteLine(myListString.ToString()); Console.WriteLine(); myListString[4] = "Soyancho"; myListString.Insert(3, "Angel"); Console.WriteLine(myListString.ToString()); Console.WriteLine(); myListString.Delete(1); Console.WriteLine(myListString.ToString()); Console.WriteLine(); myListString.Clear(); Console.WriteLine(myListString.ToString()); Console.WriteLine(); }
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()); }
static void Main() { var test = new GenericList <int>(); for (int i = 0; i < 11; i++) { test.Add(i); } Console.WriteLine(test.ToString()); test.AddAtIndex(4, 56); Console.WriteLine(test.ToString()); Console.WriteLine(test.Max()); // Testing Min and Max methods Task 7 Console.WriteLine(test.Min()); }
static void Main() { var list = new GenericList <int>(5); list.Add(10); list.Add(34); list.Add(27); list.Insert(1, 23); list.Insert(1, 443); list.Insert(1, 463); Console.WriteLine(list); Console.WriteLine(list.Min()); Console.WriteLine(list.Max()); }
static void Main() { var list = new GenericList <int>(5); list.Add(5); list.Add(10); list.Add(20); list.Insert(1, 123); list.Add(-100); Console.WriteLine(list); Console.WriteLine(list.Min()); Console.WriteLine(list.Max()); }
public static void Main() { GenericList <int> exampleGeneric = new GenericList <int>(3); Console.WriteLine("GenericList capacity = " + exampleGeneric.Capacity); Console.WriteLine("ToString method result = " + exampleGeneric.ToString()); Console.WriteLine(new string('=', 30)); exampleGeneric.Add(3); exampleGeneric.Add(4); exampleGeneric.Add(7); exampleGeneric.Add(12); Console.WriteLine("ToString method result after adding elements = " + exampleGeneric.ToString()); Console.WriteLine(new string('=', 30)); Console.WriteLine("The element at index 0 is " + exampleGeneric.GetItemAtIndex(0)); Console.WriteLine("The element at index 1 is " + exampleGeneric.GetItemAtIndex(1)); Console.WriteLine("The element at index 2 is " + exampleGeneric.GetItemAtIndex(2)); Console.WriteLine("The element at index 3 is " + exampleGeneric.GetItemAtIndex(3)); Console.WriteLine(new string('=', 30)); exampleGeneric.RemoveElementAtIndex(0); Console.WriteLine("ToString method result after removing element at index 0 = " + exampleGeneric.ToString()); exampleGeneric.RemoveElementAtIndex(2); Console.WriteLine("ToString method result after removing element at index 2 = " + exampleGeneric.ToString()); Console.WriteLine(new string('=', 30)); exampleGeneric.InsertElementAtIndex(3, 0); Console.WriteLine("ToString method result after inserting value of 3 at index 0 = " + exampleGeneric.ToString()); exampleGeneric.InsertElementAtIndex(12, 2); Console.WriteLine("ToString method result after inserting value of 12 at index 1 = " + exampleGeneric.ToString()); Console.WriteLine(new string('=', 30)); Console.WriteLine("The index of 12 is " + exampleGeneric.FindElement(12)); Console.WriteLine("The index of 3 is " + exampleGeneric.FindElement(3)); Console.WriteLine("The index of 4 is " + exampleGeneric.FindElement(4)); Console.WriteLine(new string('=', 30)); Console.WriteLine("The min value is " + exampleGeneric.Min()); Console.WriteLine("The max value is " + exampleGeneric.Max()); Console.WriteLine(new string('=', 30)); exampleGeneric.Clear(); Console.WriteLine("ToString method result after clearing = " + exampleGeneric.ToString()); Console.WriteLine(new string('=', 30)); }
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()); }
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); }
public static void Main() { var firstList = new GenericList <int>(); for (int i = 0; i < 6; i++) { firstList.Add(i); } Console.WriteLine("Initialize GenericList"); Console.WriteLine(firstList); Console.WriteLine("Add item at index 3"); firstList.AddAtIndex(10, 3); Console.WriteLine(firstList); Console.WriteLine("Deleted item at index 3"); firstList.DeleteAtIndex(3); Console.WriteLine(firstList); Console.WriteLine("Min item In the array is: {0}", firstList.Min()); Console.WriteLine("Max item In the array is: {0}", firstList.Max()); }
static void Main() { //Empty constructor with the default capacity. If some value is written like parameter in the constructor //the capacity will be equal to this parameter. GenericList <int> col = new GenericList <int>(); //add some elements to the collection col.Add(2); col.Add(77); col.Add(33); col.Add(7447); Console.WriteLine("the elements of the collection: " + col.ToString()); Console.WriteLine("The capacity = " + col.Capacity); Console.WriteLine("The element at index[1] is: " + col[1]); //set new value at index [1] col[1] = 666; Console.WriteLine("The new value in index [1] is: " + col[1]); Console.WriteLine("Count of the collection = " + col.Count); //Removing element at index [0] col.RemoveAt(0); Console.WriteLine(); Console.WriteLine("Collection after removing: " + col.ToString()); Console.WriteLine("Count of the collection after removing: " + col.Count); //inserting element in the collection Console.WriteLine("collection before inserting: " + col.ToString()); col.InsertAt(2, 9999999); Console.WriteLine("collection after inserting: " + col.ToString()); //Clear and print capacity and Count col.Clear(); Console.WriteLine(); Console.WriteLine("After the clear -----------------------"); Console.WriteLine("Capacity = " + col.Capacity); Console.WriteLine("Count = " + col.Count); Console.WriteLine("Collection: " + col.ToString()); Console.WriteLine(); //finding index by its value if exist. If do not exist return -1 col.Add(2); col.Add(3); col.Add(-1); col.Add(-99); //print the collection after adding some values Console.WriteLine("Collection: " + col.ToString()); int max = col.Max(); Console.WriteLine("max = " + max); int min = col.Min(); Console.WriteLine("min = " + min); int value = 3; int index = col.indexOf(value); if (index > 0) { Console.WriteLine("The element with value: {0} is on index: {1}", value, index); } else { Console.WriteLine("The element with value: {0} is not found.", value); } }
static void Main() { Console.WriteLine("Initialize GenericList<double> testList and set capacity to 5"); int capacity = 5; Console.WriteLine("OK"); GenericList <double> testList = new GenericList <double>(capacity); for (int i = 0; i < capacity; i++) { testList.AddElement(i * 2.35); } Console.WriteLine("\n[Trying to insert one more element 35.6 above specified capacity]"); try { testList.AddElement(35.6); Console.WriteLine("OK"); } catch (Exception ex) { Console.WriteLine(String.Format("[Expected exception message]:\n{0}", ex.Message)); } Console.WriteLine("testList.ToString() output: {0}", testList); Console.WriteLine("\n[Removing first element!]"); testList.RemoveElement(0); Console.WriteLine("testList.ToString() output: {0}", testList); Console.WriteLine("\n[Trying to insert at index -1]"); try { testList.InsertElement(2.5, -1); } catch (Exception ex) { Console.WriteLine(String.Format("[Expected exception message]:\n{0}", ex.Message)); } Console.WriteLine("testList.ToString() output: {0}", testList); Console.WriteLine("\n[Trying to insert 17.5 at index 1]"); testList.InsertElement(17.5, 1); Console.WriteLine("testList.ToString() output: {0}", testList); Console.WriteLine("\n[Trying to insert 2.5 at index 1 when list is at max capacity]:"); try { testList.InsertElement(2.5, 1); Console.WriteLine("OK"); } catch (Exception ex) { Console.WriteLine(String.Format("[Expected exception message]:\n{0}", ex.Message)); } GenericList <double> testList2 = new GenericList <double>(1); Console.WriteLine("\n[Trying to remove element from empty list]"); try { testList2.RemoveElement(0); } catch (Exception ex) { Console.WriteLine(String.Format("[Expected exception message]:\n{0}", ex.Message)); } Console.WriteLine("\n[Get element at index 1]"); Console.WriteLine("testList.ToString() output: {0}", testList); Console.WriteLine("testList.GetElement(1) output: {0}", testList.GetElement(1)); Console.WriteLine("\n[Get element at index -1]"); try { testList.GetElement(-1); } catch (Exception ex) { Console.WriteLine(String.Format("[Expected exception message]:\n{0}", ex.Message)); } Console.WriteLine("\n[Find element 2.6 index]"); Console.WriteLine("testList.ToString() output: {0}", testList); Console.WriteLine("testList.FindElement(2.6) output: {0}", testList.FindElement(2.6)); Console.WriteLine("\n[Find element 2.35 index]"); Console.WriteLine("testList.ToString() output: {0}", testList); Console.WriteLine("testList.FindElement(2.35) output: {0}", testList.FindElement(2.35)); Console.WriteLine("\n[Return element at index 2]"); Console.WriteLine("testList.ToString() output: {0}", testList); Console.WriteLine("testList[2] output: {0}", testList[2]); Console.WriteLine("\n[Return max element]"); Console.WriteLine("[Insert 50 at index 2]"); testList.InsertElement(50, 2); Console.WriteLine(testList); Console.WriteLine("testList.Max() output: {0}", testList.Max()); Console.WriteLine("\n[Return min element]"); Console.WriteLine("[Insert -50 at index 4]"); testList.InsertElement(-50, 4); Console.WriteLine("testList.ToString() output: {0}", testList); Console.WriteLine("testList.Min() output: {0}", testList.Min()); Console.WriteLine("\n[Clear list]"); testList.ClearList(); Console.WriteLine("testList.ToString() output: {0}", testList); }
public static void Main() { // Testing with list of integers GenericList <int> listOfIntegers = new GenericList <int>(); // Adding elements listOfIntegers.AddElement(8); listOfIntegers.AddElement(9); listOfIntegers.AddElement(5); listOfIntegers.AddElement(7); // Testing the indexator Console.Write("The list: "); for (int i = 0; i < listOfIntegers.Count; i++) { Console.Write(listOfIntegers[i]); if (i != listOfIntegers.Count - 1) { Console.Write(", "); } } Console.WriteLine("\n"); // Inserting elements listOfIntegers.InsertElement(2, 10); listOfIntegers.InsertElement(4, 11); Console.WriteLine("After inserting elements: {0}", listOfIntegers.ToString()); Console.WriteLine(); // Removing elements listOfIntegers.RemoveElement(1); listOfIntegers.RemoveElement(3); Console.WriteLine("After removing elements: {0}", listOfIntegers.ToString()); Console.WriteLine(); Console.WriteLine("Max: {0}", listOfIntegers.Max <int>()); Console.WriteLine("Min: {0}", listOfIntegers.Min <int>()); // Finding element Console.WriteLine(listOfIntegers.FindElement(7)); // Clear the list listOfIntegers.ClearGenericList(); if (listOfIntegers.Count == 0) { Console.WriteLine("\nThe list is empty"); } Console.WriteLine(new string('-', 50)); // Testing with list of integers GenericList <string> listOfStrings = new GenericList <string>(); // Adding elements listOfStrings.AddElement("Testing"); listOfStrings.AddElement("some"); listOfStrings.AddElement("variables"); listOfStrings.AddElement("with strings"); // Testing the indexator Console.Write("\nThe list: "); for (int i = 0; i < listOfStrings.Count; i++) { Console.Write(listOfStrings[i]); if (i != listOfStrings.Count - 1) { Console.Write(", "); } } Console.WriteLine("\n"); // Inserting elements listOfStrings.InsertElement(2, "Hi from Penka"); listOfStrings.InsertElement(4, "LOL"); Console.WriteLine("After inserting elements: {0}", listOfStrings.ToString()); Console.WriteLine(); // Removing elements listOfStrings.RemoveElement(1); listOfStrings.RemoveElement(3); Console.WriteLine("After removing elements: {0}", listOfStrings.ToString()); Console.WriteLine(); // Compare strings by the ASCII table Console.WriteLine("Max: {0}", listOfStrings.Max <string>()); Console.WriteLine("Min: {0}", listOfStrings.Min <string>()); // Finding element Console.WriteLine(listOfStrings.FindElement("LOL")); // Clear the list listOfStrings.ClearGenericList(); if (listOfStrings.Count == 0) { Console.WriteLine("\nThe list is empty"); } }