diff --git a/Battleship/Battleship/SetGeneric.cs b/Battleship/Battleship/SetGeneric.cs index 49e4943..791d406 100644 --- a/Battleship/Battleship/SetGeneric.cs +++ b/Battleship/Battleship/SetGeneric.cs @@ -6,6 +6,10 @@ using System.Threading.Tasks; namespace Battleship.Generics { +<<<<<<< HEAD +======= + +>>>>>>> 504798d4c4853a3db22a25ff6cf613a36640f1c3 internal class SetGeneric where T : class { @@ -20,8 +24,46 @@ namespace Battleship.Generics public bool Insert(T ship) { +<<<<<<< HEAD if(_places.Count == _maxCount) { +======= + if (_places[Count - 1] != null) + return -1; + return Insert(ship,0); + } + /// + /// Добавление объекта в набор на конкретную позицию + /// /// + /// Добавляемый автомобиль + /// Позиция + /// + public int Insert(T ship, int position) + { + if (!(position >= 0 && position < Count)) + return -1; + if (_places[position] != null) + { + int ind = position; + while (ind < Count && _places[ind] != null) + ind++; + if (ind == Count) + return -1; + for (int i = ind - 1; i >= position; i--) + _places[i + 1] = _places[i]; + } + _places[position] = ship; + return position; + } + /// + /// Удаление объекта из набора с конкретной позиции + /// + /// + /// + public bool Remove(int position) + { + if (!(position >= 0 && position < Count) || _places[position] == null) +>>>>>>> 504798d4c4853a3db22a25ff6cf613a36640f1c3 return false; } Insert(ship, 0); @@ -30,6 +72,7 @@ namespace Battleship.Generics public bool Insert(T ship, int position) { +<<<<<<< HEAD if(!(position >= 0 && position <= Count && _places.Count < _maxCount)) { return false; @@ -76,6 +119,11 @@ namespace Battleship.Generics } } +======= + if (!(position >= 0 && position < Count)) + return null; + return _places[position]; +>>>>>>> 504798d4c4853a3db22a25ff6cf613a36640f1c3 } } }