доработка базовой части (Insert, Remove)
This commit is contained in:
parent
51262a3eb0
commit
6f8d738bf3
@ -29,7 +29,7 @@
|
||||
/// <returns></returns>
|
||||
public int Insert(T locomotive, int position)
|
||||
{
|
||||
if (position < 0 || position > _maxCount)
|
||||
if (position < 0 || position > Count + 1)
|
||||
{
|
||||
return position;
|
||||
}
|
||||
@ -38,23 +38,9 @@
|
||||
_places.Add(locomotive);
|
||||
return 0;
|
||||
}
|
||||
if (position == 0)
|
||||
{
|
||||
for (int i = Count; i >= 1; i--)
|
||||
{
|
||||
_places.Insert(i, _places[i - 1]);
|
||||
_places.RemoveAt(i - 1);
|
||||
}
|
||||
_places.Insert(0, locomotive);
|
||||
return 0;
|
||||
}
|
||||
if (_places[position] == null)
|
||||
{
|
||||
_places.Insert(position, locomotive);
|
||||
return position;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
@ -62,12 +48,12 @@
|
||||
/// <returns></returns>
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (_places[position] == null)
|
||||
if (position > Count || _places[position] == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var result = _places[position];
|
||||
_places[position] = null;
|
||||
_places.RemoveAt(position);
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
|
Loading…
Reference in New Issue
Block a user