Bondarenko M.S. Lab Work 3 #8

Merged
eegov merged 12 commits from LabWork_03 into LabWork_02 2022-11-07 12:10:38 +04:00
3 changed files with 9 additions and 21 deletions
Showing only changes of commit 3e7c3c7f5f - Show all commits

View File

@ -55,7 +55,7 @@ namespace WarmlyShip
if (form.ShowDialog() == DialogResult.OK)
{
DrawningObjectShip ship = new(form.SelectedShip);
if (_mapShipCollectionGeneric + ship == 1)
if (_mapShipCollectionGeneric + ship > -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapShipCollectionGeneric.ShowSet();
@ -78,7 +78,7 @@ namespace WarmlyShip
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapShipCollectionGeneric - pos == 1)
if (_mapShipCollectionGeneric - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _mapShipCollectionGeneric.ShowSet();

View File

@ -32,7 +32,7 @@ namespace WarmlyShip
return map._setShips.Insert(ship);
}
public static int operator -(MapWithSetShipGeneric<T, U> map, int position)
public static T operator -(MapWithSetShipGeneric<T, U> map, int position)
{
return map._setShips.Remove(position);
}

View File

@ -26,25 +26,12 @@ namespace WarmlyShip
public int 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 1;
}
return 0;
return Insert(ship, 0);
}
public int Insert(T ship, int position)
{
if (position < 0 || position > _places.Length) return 0;
if (position < 0 || position > _places.Length) return -1;
if (_places[position] != null && CanInsert(position))
{
for (int i = _places.Length - 1; i > position; --i)
@ -57,13 +44,14 @@ namespace WarmlyShip
}
}
_places[position] = ship;
return 1;
return position;
}
public int Remove(int position)
public T Remove(int position)
{
T DelElement = _places[position];
Review

Нет проверки, что индекс не выходит за границы массива

Нет проверки, что индекс не выходит за границы массива
_places[position] = null;
return 1;
return DelElement;
}
public T Get(int position)