Compare commits

..

2 Commits

Author SHA1 Message Date
sqdselo
74c7268d4f борьба с конфликтами 2024-06-06 10:42:18 +04:00
sqdselo
bb32f6d69e борьба с конфликтами завершена 2024-06-06 10:12:34 +04:00
3 changed files with 71 additions and 50 deletions

View File

@ -1,11 +1,8 @@
using System;
using System.CodeDom.Compiler;
using System.Windows.Forms.VisualStyles;
using HoistingCrane.Drawning;
using HoistingCrane.Exceptions;
namespace HoistingCrane.CollectionGenericObjects;
public class ListGenericObjects<T> : ICollectionGenericObjects<T>
where T : class
public class ListGenericObjects<T> : ICollectionGenericObjects<T> where T : class
{
/// <summary>
/// Список объектов, которые храним
@ -66,39 +63,25 @@ where T : class
return Count;
}
public int Insert(T obj, int position)
{
// Проверка, что не превышено максимальное количество элементов
if (Count == _maxCount)
{
return -1;
}
// Проверка позиции
if (position >= Count || position < 0)
{
return -1;
}
_collection.Insert(position, obj);
return position;
}
public T? Remove(int position)
{
// Проверка позиции
if (position >= Count || position < 0)
{
return null;
}
T? obj = _collection[position];
_collection.RemoveAt(position);
return obj;
if (position < 0 || position >= list.Count) throw new PositionOutOfCollectionException(position);
T? temp = list[position];
list.RemoveAt(position);
return temp;
}
public IEnumerable<T?> GetItems()
{
for (int i = 0; i < Count; ++i)
for(int i = 0; i < list.Count; i++)
{
yield return _collection[i];
yield return list[i];
}
}
public void CollectionSort(IComparer<T> comparer)
{
list.Sort(comparer);
}
}
}

View File

@ -3,13 +3,15 @@
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
where T : class
{
/// <summary>
/// Массив объектов, которые храним
/// </summary>
private T?[] _collection;
public int Count => _collection.Length;
private T?[] arr;
public MassivGenericObjects()
{
arr = Array.Empty<T?>();
}
public int Count
{
get { return arr.Length; }
}
public int MaxCount
{
get
@ -30,17 +32,53 @@ where T : class
_collection = new T?[value];
}
}
}
if (arr[i] == null)
{
arr[i] = obj;
return i;
}
}
}
}
throw new CollectionOverflowException(Count);
}
catch (PositionOutOfCollectionException ex)
{
MessageBox.Show(ex.Message);
return -1;
}
catch (ObjectIsPresentInTheCollectionException ex)
{
MessageBox.Show(ex.Message);
return -1;
}
}
public CollectionType GetCollectionType => CollectionType.Massive;
/// <summary>
/// Конструктор
/// </summary>
public MassiveGenericObjects()
public T? Remove(int position)
{
_collection = Array.Empty<T?>();
if (position < 0 || position >= Count) throw new PositionOutOfCollectionException(position);
if (arr[position] == null) throw new ObjectNotFoundException(position);
T? temp = arr[position];
arr[position] = null;
return temp;
}
public IEnumerable<T?> GetItems()
{
for (int i = 0; i < arr.Length; i++)
{
yield return arr[i];
=========
>>>>>>>>> Temporary merge branch 2
}
}
public void CollectionSort(IComparer<T> comparer)
{
T[] notNullArr = arr.OfType<T>().ToArray();
Array.Sort(notNullArr, comparer);
Array.Copy(notNullArr, 0, arr, 0, notNullArr.Length);
}
}
public T? Get(int position)