Изменены типы возвращаемых значений

This commit is contained in:
Katerina881 2022-10-03 16:01:05 +04:00
parent 66371369da
commit c1dbdd80ed
3 changed files with 19 additions and 17 deletions

View File

@ -52,7 +52,7 @@ namespace Artilleries
if (form.ShowDialog() == DialogResult.OK)
{
DrawingObjectArtillery car = new(form.SelectedArtillery);
if (_mapArtilleriesCollectionGeneric + car)
if (_mapArtilleriesCollectionGeneric + car != -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxArtilleries.Image = _mapArtilleriesCollectionGeneric.ShowSet();
@ -75,7 +75,7 @@ namespace Artilleries
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapArtilleriesCollectionGeneric - pos)
if (_mapArtilleriesCollectionGeneric - pos != null)
{
MessageBox.Show("Объект удален");
pictureBoxArtilleries.Image = _mapArtilleriesCollectionGeneric.ShowSet();

View File

@ -27,14 +27,14 @@ namespace Artilleries
_map = map;
}
public static bool operator +(MapWithSetArtilleriesGeneric<T, U> map, T artillery)
public static int operator +(MapWithSetArtilleriesGeneric<T, U> map, T artillery)
{
return map._setArtilleries.Insert(artillery); // TODO
return map._setArtilleries.Insert(artillery);
}
public static bool operator -(MapWithSetArtilleriesGeneric<T, U> map, int position)
public static T operator -(MapWithSetArtilleriesGeneric<T, U> map, int position)
{
return map._setArtilleries.Remove(position); // TODO
return map._setArtilleries.Remove(position);
}
public Bitmap ShowSet()

View File

@ -17,22 +17,22 @@ namespace Artilleries
_places = new T[count];
}
public bool Insert(T artillery)
public int Insert(T artillery)
{
return Insert(artillery, 0);
}
public bool Insert(T artillery, int position)
public int Insert(T artillery, int position)
{
if (position < 0 || position >= Count)
{
return false;
return -1;
}
if (_places[position] == null)
{
_places[position] = artillery;
return true;
return position;
}
int firstNull = -1;
@ -48,27 +48,29 @@ namespace Artilleries
if (firstNull == -1)
{
return false;
return -1;
}
for (int i = firstNull; i > position; i--)
{
(_places[i], _places[i - 1]) = (_places[i - 1], _places[i]);
_places[i] = _places[i - 1];
}
_places[position] = artillery;
return true;
return position;
}
public bool Remove(int position)
public T Remove(int position)
{
if (position < 0 || position >= Count || _places[position] == null)
if (position < 0 || position >= Count)
{
return false;
return null;
}
var result = _places[position];
_places[position] = null;
return true;
return result;
}
public T Get(int position)