This commit is contained in:
Игорь Гордеев 2023-12-15 11:37:10 +04:00
parent 2fc3246df8
commit 7cfdcda5ed

View File

@ -1,4 +1,5 @@
using System;
using ProjectElectricLocomotive.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -24,7 +25,14 @@ namespace ProjectElectricLocomotive.Generics
public int Insert(T loco, int position)
{
if (position < 0 || position >= _maxCount) return -1;
if (_places.Count >= _maxCount)
throw new StorageOverflowException(_maxCount);
if (position < 0 || position >= _maxCount)
{
return -1;
}
_places.Insert(position, loco);
return position;
}
@ -34,6 +42,8 @@ namespace ProjectElectricLocomotive.Generics
return null;
T? tmp = _places[position];
if (tmp == null)
throw new LocoNotFoundException(position);
_places[position] = null;
return tmp;
}