лаб-7
This commit is contained in:
parent
f0436685a8
commit
7a2b6d4d45
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -46,16 +47,16 @@ namespace AircraftCarrier
|
||||
/// <returns></returns>
|
||||
public int Insert(T AircraftCarrier, int position)
|
||||
{
|
||||
// проверка позиции
|
||||
if (!CorrectPos(position))
|
||||
// TODO проверка позиции
|
||||
if (Count == _maxCount)
|
||||
{
|
||||
return -1;
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
}
|
||||
// вставка по позиции
|
||||
if (position < 0 || position > _maxCount) return -1;
|
||||
// TODO вставка по позиции
|
||||
_places.Insert(position, AircraftCarrier);
|
||||
return position;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
@ -63,13 +64,14 @@ namespace AircraftCarrier
|
||||
/// <returns></returns>
|
||||
public T Remove(int position)
|
||||
{
|
||||
// проверка позиции
|
||||
if (!CorrectPos(position))
|
||||
return null;
|
||||
// удаление объекта из массива, присовив элементу массива значение null
|
||||
T temp = _places[position];
|
||||
// TODO проверка позиции
|
||||
if (position >= Count || position < 0)
|
||||
{
|
||||
throw new AircraftCarrierNotFoundException(position);
|
||||
}
|
||||
T aircraftcarrier = _places[position];
|
||||
_places.RemoveAt(position);
|
||||
return temp;
|
||||
return aircraftcarrier;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
|
22
AircraftCarrier/AircraftCarrier/StorageOverflowException.cs
Normal file
22
AircraftCarrier/AircraftCarrier/StorageOverflowException.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AircraftCarrier
|
||||
{
|
||||
[Serializable]
|
||||
internal class StorageOverflowException : ApplicationException
|
||||
{
|
||||
public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: { count}") { }
|
||||
public StorageOverflowException() : base() { }
|
||||
public StorageOverflowException(string message) : base(message) { }
|
||||
public StorageOverflowException(string message, Exception exception) :
|
||||
base(message, exception)
|
||||
{ }
|
||||
protected StorageOverflowException(SerializationInfo info,
|
||||
StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user