From 0a9f5bcbb674b129cba6c66fd0cab881913453e4 Mon Sep 17 00:00:00 2001 From: sqdselo <147947144+sqdselo@users.noreply.github.com> Date: Sun, 28 Apr 2024 00:31:52 +0400 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MassivGenericObjects.cs | 60 ++++++++++--------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs index 3e2d561..39d6839 100644 --- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs @@ -1,4 +1,5 @@ -namespace HoistingCrane.CollectionGenericObjects +using System; +namespace HoistingCrane.CollectionGenericObjects { public class MassivGenericObjects : ICollectionGenericObjects where T : class { @@ -7,74 +8,77 @@ { arr = Array.Empty(); } - public int Count + public int Count { - get { return arr.Length; } - } + get { return arr.Length; } + } public int SetMaxCount { set { if (value > 0) { - arr = new T?[value]; + if (arr.Length > 0) + { + Array.Resize(ref arr, value); + } + else + { + arr = new T?[value]; + } } } } public T? Get(int position) { - if(position >= 0 && position < arr.Length) + if (position >= 0 && position < arr.Length) { return arr[position]; } - return null; + return null; } + public int Insert(T obj) { return Insert(obj, 0); } + public int Insert(T obj, int position) { - + //todo Проверка позиции if (position < 0 || position > Count) { return -1; } - int pos = position - 1; - - while (position < Count) + if (arr[position] == null) { - if (arr[position] == null) + arr[position] = obj; + return position; + } + else + { + if (Insert(obj, position + 1) != -1) { - arr[position] = obj; return position; } - position++; - } - while (pos > 0) - { - if (arr[position] == null) + if (Insert(obj, position - 1) != -1) { - arr[position] = obj; return position; } - position--; } - return -1; - } + public T? Remove(int position) { - if (position < 0 || position > Count) + if (position >= 0 && position < Count) { - return null; + T? temp = arr[position]; + arr[position] = null; + return temp; } - - T? removed_object = arr[position]; - arr[position] = null; - return removed_object; + return null; } } }