using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AirFighter { internal class SetAircraftsGeneric where T : class { private readonly T[] _places; public int Count => _places.Length; public SetAircraftsGeneric(int count) { _places = new T[count]; } public int Insert(T aircraft) { return Insert(aircraft, 0); } public int Insert(T aircraft, int position) { int emptypos = -1; if (position >= Count && position < 0) { return -1; } if (_places[position] == null) { _places[position] = aircraft; return position; } for (int i = position; i < Count; i++) { if (_places[i] == null) { emptypos = i; break; } } if (emptypos != -1) { for (int i = emptypos; i > position; i--) { _places[i] = _places[i - 1]; } _places[position] = aircraft; return position; } return -1; } public T Remove(int position) { if (position < Count && position >= 0) { T result = _places[position]; _places[position] = null; return result; } return null; } public T Get(int position) { if (position >= Count && position < 0) { return null; } return _places[position]; } } }