Допилена логика в SetAirplanesGeneric
This commit is contained in:
parent
caacb5672f
commit
340744510b
@ -36,8 +36,12 @@ namespace AirBomber
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool Insert(T airplane)
|
public bool Insert(T airplane)
|
||||||
{
|
{
|
||||||
// TODO вставка в начало набора
|
return Insert(airplane, 0);
|
||||||
return true;
|
}
|
||||||
|
|
||||||
|
private bool isCorrectPosition(int position)
|
||||||
|
{
|
||||||
|
return 0 < position && position <= Count;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в набор на конкретную позицию
|
/// Добавление объекта в набор на конкретную позицию
|
||||||
@ -47,11 +51,21 @@ namespace AirBomber
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool Insert(T airplane, int position)
|
public bool Insert(T airplane, int position)
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
int positionNullElement = position;
|
||||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
while (Get(positionNullElement) != null)
|
||||||
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
{
|
||||||
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
positionNullElement++;
|
||||||
// TODO вставка по позиции
|
}
|
||||||
|
// Если изначальная позиция была некорректной или пустых элементов справа не оказалось возвращаем false
|
||||||
|
if (!isCorrectPosition(positionNullElement))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
while (positionNullElement != position) // Смещение вправо
|
||||||
|
{
|
||||||
|
_places[positionNullElement] = _places[positionNullElement - 1];
|
||||||
|
positionNullElement--;
|
||||||
|
}
|
||||||
_places[position] = airplane;
|
_places[position] = airplane;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -62,8 +76,9 @@ namespace AirBomber
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool Remove(int position)
|
public bool Remove(int position)
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
if (!isCorrectPosition(position))
|
||||||
// TODO удаление объекта из массива, присовив элементу массива значение null
|
return false;
|
||||||
|
_places[position] = null;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -73,8 +88,7 @@ namespace AirBomber
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public T Get(int position)
|
public T Get(int position)
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
return isCorrectPosition(position) ? _places[position] : null;
|
||||||
return _places[position];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user