public void AddRange(IEnumerable <T> items) { CycledDynamicArray <T> cda = (items as CycledDynamicArray <T>); int count = (cda != null ? count = cda.Count() : items.Count()); T[] arrayToAdd = new T[count]; int j = 0; foreach (T item in items) { arrayToAdd[j++] = item; if (j == count) { break; } } int arrayToAddLength = arrayToAdd.Length; Expand(arrayToAddLength); for (int i = 0; i < arrayToAddLength; i++) { _array[_length++] = arrayToAdd[i]; } }
static void Main() { double selection; do { Console.WriteLine("3,1 LOST."); Console.WriteLine("3,2 WORD FREQUENCY."); Console.WriteLine("3,3 DYNAMIC ARRAY AND HARDCORE MODE."); Console.WriteLine("3,4 CYCLED ARRAY."); Console.WriteLine("0 Exit."); Console.WriteLine(); if (double.TryParse(Console.ReadLine(), out selection)) { switch (selection) { case 3.1: Lost.Read(); break; case 3.2: var txt = WordFrequency.Read(); Dictionary <string, int> result = WordFrequency.WordFrequence(txt); WordFrequency.Show(result); break; case 3.3: DynamicArray <int> .Show(); Console.WriteLine(); DynamicArrayHardcoreMode <int> .ShowHM(); break; case 3.4: var vs = new CycledDynamicArray <int>(new List <int> { 1, 2, 3, 4, 5 }, 5); foreach (var item in vs) { Console.WriteLine(item); } break; case 0: break; } } } while (selection != 0); }
public static void DynamicArrayPreview() { var arr1 = new int[] { 1, 2, 3, 4, 5 }; var arrCycle = new CycledDynamicArray <int>(arr1); var count = 0; foreach (var i in arrCycle) { Console.WriteLine(i); count++; if (count >= 10) { break; } } }
public static int Count <T>(this CycledDynamicArray <T> items) { int c = 0; items.isEndless = false; var e = items.GetEnumerator(); { while (e.MoveNext()) { c++; } } items.isEndless = true; return(c); }
static void Task3() { Console.WriteLine("Задание 3: свой динамический массив, и бесконечный динамический массив."); DynamicArray <string> array = new DynamicArray <string>(); array.AddRange(new string[] { "12", "23", "34", "45", "56", "67", "78", "89", "90", "011", "012", "013", "014", "015", "016", "017", "018", "019" }); CycledDynamicArray <string> array2 = new CycledDynamicArray <string>(array);//(array.Clone() as CycledDynamicArray<string>); //array2.AddRange(new string[] { "12", "23", "34", "45", "56", "67", "78", "89", "90", "011", "012", "013", "014", "015", "016", "017", "018", "019" }); array2.AddRange(array2); IEnumerable <string> ienumArray = array2; foreach (string item in ienumArray) { Console.WriteLine(item); } //array2.AddRange(array2); //array2.Remove("90"); //array.Insert("90", 17); //Console.WriteLine($"{array.Capacity} {array.Length}"); //Console.WriteLine($"{array2.Capacity} {array2.Length}"); //Console.WriteLine(array[-20]); int limit = 100; int iteration = 1; /*foreach(string value in array) * { * Console.WriteLine(value); * if(iteration++ >= limit) * { * break; * } * }*/ Console.ReadKey(); }