This commit is contained in:
Макс Бондаренко 2022-10-23 18:37:20 +04:00
parent 3f669751ff
commit 572df7efe3

View File

@ -17,16 +17,28 @@ namespace WarmlyShip
_places = new T[count];
}
public bool Insert(T ship)
{
_places[0] = ship;
return true;
}
private bool CanInsert(int position)
{
for (int i = position; i < _places.Length; ++i)
if (_places[i] != null) return true;
if (_places[i] == null) return true;
return false;
}
public bool Insert(T ship)
{
if (CanInsert(0))
{
for (int i = _places.Length - 1; i > 0; --i)
{
if (_places[i] == null)
{
_places[i] = _places[i - 1];
_places[i - 1] = null;
}
}
_places[0] = ship;
return true;
}
return false;
}