diff --git a/WarmlyShip/WarmlyShip/SetShipGeneric.cs b/WarmlyShip/WarmlyShip/SetShipGeneric.cs index 86ad35e..8c4e42f 100644 --- a/WarmlyShip/WarmlyShip/SetShipGeneric.cs +++ b/WarmlyShip/WarmlyShip/SetShipGeneric.cs @@ -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; }