82 lines
1.8 KiB
C#
82 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AirBomber
|
|
{
|
|
internal class SetAirBomberGeneric<T>
|
|
where T : class
|
|
{
|
|
private readonly List<T> _places;
|
|
|
|
public int Count => _places.Count;
|
|
|
|
private readonly int _maxCount;
|
|
|
|
public SetAirBomberGeneric(int count)
|
|
{
|
|
_maxCount = count;
|
|
_places = new List<T>();
|
|
}
|
|
|
|
public int Insert(T airBomber)
|
|
{
|
|
return Insert(airBomber, 0);
|
|
}
|
|
|
|
public int Insert(T airBomber, int position)
|
|
{
|
|
if (position < 0 || position > _maxCount)
|
|
{
|
|
return -1;
|
|
}
|
|
_places.Insert(position, airBomber);
|
|
return position;
|
|
}
|
|
|
|
public T Remove(int position)
|
|
{
|
|
if (position < 0 || position > _maxCount)
|
|
{
|
|
return null;
|
|
}
|
|
T elem = _places[position];
|
|
_places[position] = null;
|
|
return elem;
|
|
}
|
|
|
|
public T this[int position]
|
|
{
|
|
get
|
|
{
|
|
if (position < 0 || position > _maxCount)
|
|
{
|
|
return null;
|
|
}
|
|
return _places[position];
|
|
}
|
|
set
|
|
{
|
|
Insert(value, position);
|
|
}
|
|
}
|
|
|
|
public IEnumerable<T> GetAirBomber()
|
|
{
|
|
foreach (var airBomber in _places)
|
|
{
|
|
if (airBomber != null)
|
|
{
|
|
yield return airBomber;
|
|
}
|
|
else
|
|
{
|
|
yield break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|