Lab_3_Kryukov_AI_Excavator

This commit is contained in:
1SooNoo1 2023-10-10 20:46:18 +04:00
parent a75dd9c18d
commit fddb6dc9e8
2 changed files with 10 additions and 10 deletions

View File

@ -26,13 +26,13 @@ namespace ProjectExcavator.Generic
_pictureHeight = picHeight;
_collection = new SetGeneric<T>(width * height);
}
public static bool operator +(ExcavatorGenericCollection<T, U> collect, T? obj)
public static int operator +(ExcavatorGenericCollection<T, U> collect, T? obj)
{
if (obj == null)
{
return false;
return -1;
}
return collect?._collection.Insert(obj) ?? false;
return collect?._collection.Insert(obj) ?? -1;
}
public static T? operator -(ExcavatorGenericCollection<T, U> collect, int pos)
{

View File

@ -15,7 +15,7 @@ namespace ProjectExcavator
{
_places = new T?[count];
}
public bool Insert(T excavator)
public int Insert(T excavator)
{
int i = 0;
for (; i < _places.Length; i++)
@ -26,18 +26,18 @@ namespace ProjectExcavator
}
}
if (i == _places.Length)
return false;
return -1;
for (; i > 0; i--)
{
_places[i] = _places[i - 1];
}
_places[i] = excavator;
return true;
return Insert(excavator,0);
}
public bool Insert(T excavator, int position)
public int Insert(T excavator, int position)
{
if (position < 0 || position >= _places.Length)
return false;
return -1;
for (; position < _places.Length; position++)
{
if (_places[position] == null)
@ -46,13 +46,13 @@ namespace ProjectExcavator
}
}
if (position == _places.Length)
return false;
return -1;
for (; position > 0; position--)
{
_places[position] = _places[position - 1];
}
_places[position] = excavator;
return true;
return position;
}
public bool Remove(int position) {
if (position >= _places.Length || position<0)