This commit is contained in:
Yunusov_Niyaz 2023-10-21 15:11:32 +04:00
parent 0dade24b81
commit be4a8c4f1d
2 changed files with 15 additions and 17 deletions

View File

@ -52,11 +52,11 @@ namespace ProjectTrolleybus.Generics
/// <param name="collect"></param>
/// <param name="obj"></param>
/// <returns></returns>
public static BusesGenericCollection<T, U>? operator +(BusesGenericCollection<T, U>? collect, T? obj)
public static int operator +(BusesGenericCollection<T, U>? collect, T? obj)
{
if (obj != null)
collect?._collection.Insert(obj);
return collect;
if (obj == null || collect == null)
return -1;
return collect._collection.Insert(obj);
}
/// <summary>
/// Перегрузка оператора вычитания
@ -64,14 +64,12 @@ namespace ProjectTrolleybus.Generics
/// <param name="collect"></param>
/// <param name="pos"></param>
/// <returns></returns>
public static BusesGenericCollection<T, U>? operator -(BusesGenericCollection<T, U> collect, int pos)
public static bool operator -(BusesGenericCollection<T, U> collect, int pos)
{
T? obj = collect._collection.Get(pos);
if (obj != null)
{
collect?._collection.Remove(pos);
}
return collect;
T? obj = collect?._collection.Get(pos);
if (obj == null || collect == null)
return false;
return collect._collection.Remove(pos);
}
/// <summary>
/// Получение объекта IMoveableObject

View File

@ -18,29 +18,29 @@ namespace ProjectTrolleybus.Generics
_places = new T?[count];
}
public bool Insert(T trolleybus)
public int Insert(T trolleybus)
{
if (_places[Count - 1] != null)
return false;
return -1;
return Insert(trolleybus, 0);
}
public bool Insert(T trolleybus, int position)
public int Insert(T trolleybus, int position)
{
if (!(position >= 0 && position < Count))
return false;
return -1;
if (_places[position] != null)
{
int ind = position;
while (ind < Count && _places[ind] != null)
ind++;
if (ind == Count)
return false;
return -1;
for (int i = ind - 1; i >= position; i--)
_places[i + 1] = _places[i];
}
_places[position] = trolleybus;
return true;
return position;
}
public bool Remove(int position)