From 6c82157b441bc0683eb4f5f9ba9c7c509d4d5dbb Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 22 Oct 2023 13:52:13 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BE=D0=B4=20=D0=BA=D0=BB=D0=B0?= =?UTF-8?q?=D1=81=D1=81=D0=B0=20SetGeneric.=20=D0=9D=D0=B0=D1=87=D0=B0?= =?UTF-8?q?=D0=BB=D0=BE=20Lab4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/SetGeneric.cs | 46 +++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/AirBomber/AirBomber/SetGeneric.cs b/AirBomber/AirBomber/SetGeneric.cs index b1b0f54..1188285 100644 --- a/AirBomber/AirBomber/SetGeneric.cs +++ b/AirBomber/AirBomber/SetGeneric.cs @@ -12,18 +12,23 @@ namespace AirBomber /// /// Массив объектов, которые храним /// - private readonly T?[] _places; + private readonly List _places; /// /// Количество объектов в массиве /// - public int Count => _places.Length; + public int Count => _places.Count; + /// + /// Максимальное количество объектов в списке + /// + private readonly int _maxCount; /// /// Конструктор /// /// public SetGeneric(int count) { - _places = new T?[count]; + _maxCount = count; + _places = new List(count); } /// /// Добавление объекта в набор @@ -96,15 +101,38 @@ namespace AirBomber /// /// /// - public T? Get(int position) + public T? this[int position] { - // TODO проверка позиции DONE - if (position < 0 || position >= Count) + get { - return null; + // TODO проверка позиции DONE + if (position < 0 || position >= Count) + { + return null; + } + return _places[position]; + } + set + { + // TODO проверка позиции + // TODO проверка свободных мест в списке + // TODO вставка в список по позиции + } + } + /// + /// Проход по списку + /// + /// + public IEnumerable GetCars(int? maxCars = null) + { + for (int i = 0; i < _places.Count; ++i) + { + yield return _places[i]; + if (maxCars.HasValue && i == maxCars.Value) + { + yield break; + } } - return _places[position]; } - } }