using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Liner.Generics { /// /// Параметризованный набор объектов /// /// public class SetGeneric where T : class { /// /// Массив объектов, которые храним /// private readonly T?[] _places; /// /// Количество объектов в массиве /// public int Count => _places.Length; /// /// Конструктор /// /// public SetGeneric(int count) { _places = new T?[count]; } /// /// Добавление объекта в набор /// /// Добавляемый лайнер /// public int Insert(T liner) { int nulli = 0; while (_places[nulli] != null) { nulli++; if(nulli == _places.Length) { return -1; // нет пустого места } } //сдвиг for(int i = nulli; i > 0; i--) { _places[i] = _places[i - 1]; } _places[0] = liner; return 0; } /// /// Добавление объекта в набор на конкретную позицию /// /// Добавляемый лайнер /// Позиция /// public int Insert(T liner, int position) { if (position < 0 || position > _places.Length) { return -1; } if (_places[position] != null) { int nulli = position; while (_places[nulli] != null) { nulli++; if (nulli == _places.Length) { return -1; // нет пустого места } } } _places[position] = liner; return position; } /// /// Удаление объекта из набора с конкретной позиции /// /// /// public bool Remove(int position) { if (position < 0 || position > _places.Length) { return false; } _places[position] = null; return true; } /// /// Получение объекта из набора по позиции /// /// /// public T? Get(int position) { if (position < 0 || position > _places.Length) { return null; } return _places[position]; } } }