PIbd-12_Smolin_D.S. LabWork04 Simple #4 #5

Closed
d.smolinn wants to merge 4 commits from Lab4 into Lab3
Showing only changes of commit 73d75767ca - Show all commits

View File

@ -21,7 +21,9 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
/// </summary>
private int _maxCount;
public int Count => _collection.Count;
public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } }
/// <summary>
/// Конструктор
/// </summary>
@ -29,55 +31,43 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
{
_collection = new();
}
public T? Get(int position)
{
if (position < 0 || position >= _collection.Count)
if (position >= 0 && position < Count)
{
throw new IndexOutOfRangeException("Недопустимая позиция");
return _collection[position];
}
return _collection[position];
}
public bool Insert(T obj)
{
if (_collection.Count >= _maxCount)
else
{
return false;
return null;
}
_collection.Add(obj);
return true;
}
public bool Insert(T obj, int position)
public int Insert(T obj)
{
if (_collection.Count >= _maxCount || position < 0 || position > _collection.Count)
if (Count == _maxCount) { return -1; }
_collection.Add(obj);
return Count;
}
public int Insert(T obj, int position)
{
if (position < 0 || position >= Count || Count == _maxCount)
{
return false;
return -1;
}
_collection.Insert(position, obj);
return true;
return position;
}
public bool Remove(int position)
public T Remove(int position)
{
if (position < 0 || position >= _collection.Count)
{
return false;
}
if (position >= Count || position < 0) return null;
T obj = _collection[position];
_collection.RemoveAt(position);
return true;
}
int ICollectionGenericObjects<T>.Insert(T obj)
{
throw new NotImplementedException();
}
int ICollectionGenericObjects<T>.Insert(T obj, int position)
{
throw new NotImplementedException();
}
T ICollectionGenericObjects<T>.Remove(int position)
{
throw new NotImplementedException();
return obj;
}
}