This commit is contained in:
rakhaliullov 2024-05-01 17:20:31 +03:00
parent 44f7ef01e8
commit a272e8dbd0

View File

@ -56,63 +56,68 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
/// <returns></returns>
public T? Get(int position)
{
if (position < 0 || position >= _collection.Length)
throw new PositionOutOfCollectionException(position);
if (_collection[position] == null)
throw new ObjectNotFoundException(position);
// проверка позиции
if (position >= _collection.Length || position < 0)
{
return null;
}
return _collection[position];
}
public int Insert(T obj)
{
for (int i = 0; i < _collection.Length; i++)
// вставка в свободное место набора
int index = 0;
while (index < _collection.Length)
{
if (_collection[i] == null)
if (_collection[index] == null)
{
_collection[i] = obj;
return i;
_collection[index] = obj;
return index;
}
index++;
}
throw new CollectionOverflowException(_collection.Length);
return -1;
}
public bool Insert(T obj, int position)
public int Insert(T obj, int position)
{
if (position < 0 || position >= _collection.Length) // проверка позиции
throw new PositionOutOfCollectionException(position);
if (_collection[position] == null) // Попытка вставить на указанную позицию
if (position >= _collection.Length || position < 0)
{ return -1; }
if (_collection[position] == null)
{
_collection[position] = obj;
return true;
return position;
}
for (int i = position; i < _collection.Length; i++) // попытка вставить объект на позицию после указанной
int index;
for (index = position + 1; index < _collection.Length; ++index)
{
if (_collection[i] == null)
if (_collection[index] == null)
{
_collection[i] = obj;
return true;
_collection[position] = obj;
return position;
}
}
for (int i = 0; i < position; i++) // попытка вставить объект на позицию до указанной
{
if (_collection[i] == null)
{
_collection[i] = obj;
return true;
}
}
throw new CollectionOverflowException(_collection.Length);
}
for (index = position - 1; index >= 0; --index)
{
if (_collection[index] == null)
{
_collection[position] = obj;
return position;
}
}
return -1;
}
public T Remove(int position)
{
if (position < 0 || position >= _collection.Length) // проверка позиции
throw new PositionOutOfCollectionException(position);
if (_collection[position] == null)
throw new ObjectNotFoundException(position);
T temp = _collection[position];
if (position >= _collection.Length || position < 0)
{ return null; }
T DrawningAircraft = _collection[position];
_collection[position] = null;
return temp;
return DrawningAircraft;
}
public IEnumerable<T?> GetItems()
{
for (int i = 0; i < _collection.Length; ++i)