101
This commit is contained in:
parent
3f669751ff
commit
572df7efe3
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user