static void Main(string[] args) { int option = -1; while (option != 0) { Console.Clear(); Console.WriteLine("1) Однонаправленные списки."); Console.WriteLine("2) Двунаправленные списки."); Console.WriteLine("3) Дерево."); Console.WriteLine("4) Коллекция(двунаправленный список)."); Console.WriteLine("0) Выход."); Console.WriteLine("Выберите опцию: "); option = Input.Int(0, 5); switch (option) { case 0: return; break; case 1: Menu1(); break; case 2: Menu2(); break; case 3: Menu3(); break; case 4: Menu4(); break; } } MyCollection <int> myCol = new MyCollection <int>(); myCol.Add(20); myCol.Add(10); myCol.Add(220); myCol.Add(250); myCol.Add(240); foreach (int i in myCol) { Console.WriteLine(i); } /*MyCollection<int> mycol = new MyCollection<int>(); * mycol.Add(10); * mycol.Add(132312); * foreach (int i in mycol) * Console.WriteLine(i);*/ }
public void Add(T data) { if (Count == 1) { Next = new MyCollection <T>(); Next.Data = data; Next.Previous = this; Count++; return; } Count++; Next.Add(data); }
static void Menu4() { int option = -1; while (option != 0) { Console.Clear(); Console.WriteLine("1) Создать коллекцию."); Console.WriteLine("2) Вывести коллекцию."); Console.WriteLine("3) Удалить элемент."); Console.WriteLine("4) Добавить элемент."); Console.WriteLine("5) Вывести кол-во элементов."); Console.WriteLine("6) Найти элемент."); Console.WriteLine("7) Удалить коллекцию из памяти."); Console.WriteLine("0) Выход."); Console.WriteLine("Выберите опцию: "); option = Input.Int(0, 8); switch (option) { case 0: return; break; case 1: Console.WriteLine("Введите размер коллекции: "); int n = Input.Int(0, 10000000); for (int i = 0; i < n; i++) { if (i == 0) { myCollection = new MyCollection <Country>(new Country()); } else { myCollection.Add(new Country()); } } Console.WriteLine("Коллекция создана."); break; case 2: if (myCollection == null) { Console.WriteLine("Объект пуст."); } else { foreach (Country country in myCollection) { country.Print(); } } break; case 3: Console.WriteLine("Введите элемент для удаления: "); if (!MyCollection <Country> .Remove(ref myCollection, new Country())) { Console.WriteLine("Объект не найден"); } else { Console.WriteLine("Объект удален"); } break; case 4: Console.WriteLine("Введите элемент для добавления: "); myCollection.Add(new Country()); break; case 5: Console.WriteLine("Кол-во элементов: " + myCollection.Count); break; case 6: Console.WriteLine("Введите элемент для поиска: "); if (myCollection.Contains(new Country()) == -1) { Console.WriteLine("Элемент не найден"); } else { Console.WriteLine("Элемент найден"); } break; case 7: myCollection.Dispose(); myCollection = null; Console.WriteLine("Список удален из памяти"); break; } Console.ReadKey(); } }