Готовая Лаб3

This commit is contained in:
Данила Мочалов 2022-10-03 16:17:27 +04:00
parent e1b431152b
commit ca917f0511
3 changed files with 14 additions and 13 deletions

View File

@ -55,7 +55,7 @@ namespace Locomotive
if (form.ShowDialog() == DialogResult.OK)
{
DrawningObjectLocomotive locomotive = new(form.SelectedLocomotive);
if (_mapLocomotivesCollectionGeneric + locomotive)
if (_mapLocomotivesCollectionGeneric + locomotive != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowSet();
@ -78,7 +78,7 @@ namespace Locomotive
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapLocomotivesCollectionGeneric - pos)
if (_mapLocomotivesCollectionGeneric - pos is not null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowSet();

View File

@ -33,12 +33,12 @@ namespace Locomotive
_map = map;
}
/// Перегрузка оператора сложения
public static bool operator +(MapWithSetLocomotivesGeneric<T, U> map, T locomotive)
public static int operator +(MapWithSetLocomotivesGeneric<T, U> map, T locomotive)
{
return map._setLocomotives.Insert(locomotive);
}
/// Перегрузка оператора вычитания
public static bool operator -(MapWithSetLocomotivesGeneric<T, U> map, int position)
public static T operator -(MapWithSetLocomotivesGeneric<T, U> map, int position)
{
return map._setLocomotives.Remove(position);
}

View File

@ -19,19 +19,19 @@ namespace Locomotive
_places = new T[count];
}
/// Добавление объекта в набор
public bool Insert(T locomotive)
public int Insert(T locomotive)
{
return Insert(locomotive, 0);
}
/// Добавление объекта в набор на конкретную позицию
public bool Insert(T locomotive, int position)
public int Insert(T locomotive, int position)
{
if (position >= _places.Length|| position < 0) return false;
if (position >= _places.Length|| position < 0) return -1;
if (_places[position] == null)
{
_places[position] = locomotive;
return true;
return position;
}
int emptyEl = -1;
@ -47,7 +47,7 @@ namespace Locomotive
if (emptyEl == -1)
{
return false;
return -1;
}
for (int i = emptyEl; i > position; i--)
@ -55,14 +55,15 @@ namespace Locomotive
_places[i] = _places[i - 1];
}
_places[position] = locomotive;
return true;
return position;
}
/// Удаление объекта из набора с конкретной позиции
public bool Remove(int position)
public T Remove(int position)
{
if (position >= _places.Length || position < 0) return false;
if (position >= _places.Length || position < 0) return null;
T result = _places[position];
_places[position] = null;
return true;
return result;
}
/// Получение объекта из набора по позиции
public T Get(int position)