Bondarenko M.S. Lab Work 3 #8

Merged
eegov merged 12 commits from LabWork_03 into LabWork_02 2022-11-07 12:10:38 +04:00
Showing only changes of commit 572df7efe3 - Show all commits

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;
}