From 9aec819091d6c5544d4a97e63a53877b8fc5bd63 Mon Sep 17 00:00:00 2001 From: gettterot Date: Sun, 24 Mar 2024 16:26:53 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BD=D0=B0=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D0=BE=D0=B5=20=D0=B7=D0=B0=D0=BA=D1=80=D0=B5=D0=BF=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B2=D0=B5=D1=82=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 9 +-- .../ICollectionGenericObjects.cs | 6 +- .../MassiveGenericObjects.cs | 69 +++++++++++-------- .../ProjectLiner/FormLinerCollection.cs | 4 +- 4 files changed, 50 insertions(+), 38 deletions(-) diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs index 0e550fc..5076923 100644 --- a/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs @@ -57,9 +57,10 @@ namespace ProjectLiner.CollectionGenericObjects /// Компания /// Добавляемый объект /// - public static bool operator +(AbstractCompany company, DrawningCommonLiner Liner) + + public static int operator +(AbstractCompany company, DrawningCommonLiner airplan) { - return company._collection?.Insert(Liner) ?? false; + return company._collection.Insert(airplan); } /// @@ -68,9 +69,9 @@ namespace ProjectLiner.CollectionGenericObjects /// Компания /// Номер удаляемого объекта /// - public static bool operator -(AbstractCompany company, int position) + public static DrawningCommonLiner operator -(AbstractCompany company, int position) { - return company._collection?.Remove(position) ?? false; + return company._collection.Remove(position); } /// diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/ICollectionGenericObjects.cs index 9e2ed2f..776e2ad 100644 --- a/ProjectLiner/ProjectLiner/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -22,7 +22,7 @@ /// /// Добавляемый объект /// true - вставка прошла удачно, false - вставка не удалась - bool Insert(T obj); + int Insert(T obj); /// /// Добавление объекта в коллекцию на конкретную позицию @@ -30,14 +30,14 @@ /// Добавляемый объект /// Позиция /// true - вставка прошла удачно, false - вставка не удалась - bool Insert(T obj, int position); + int Insert(T obj, int position); /// /// Удаление объекта из коллекции с конкретной позиции /// /// Позиция /// true - удаление прошло удачно, false - удаление не удалось - bool Remove(int position); + T? Remove(int position); /// /// Получение объекта по позиции diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs index 9ed2684..f668f85 100644 --- a/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs @@ -12,7 +12,7 @@ namespace ProjectLiner.CollectionGenericObjects /// Массив объектов, которые храним /// private T?[] _collection; - + public int Count => _collection.Length; public int SetMaxCount @@ -48,63 +48,74 @@ namespace ProjectLiner.CollectionGenericObjects return _collection[position]; } - public bool Insert(T obj) + public int Insert(T obj) { for (int i = 0; i < Count; i++) { if (_collection[i] == null) { _collection[i] = obj; - return true; + return i; } } - return false; + return -1; } - public bool Insert(T obj, int position) + public int Insert(T obj, int position) { if (position < 0 || position >= Count) - return false; - - if (_collection[position] == null) { - _collection[position] = obj; - return true; + return -1; } - int temp = position + 1; - while (temp < Count) + if (_collection[position] != null) { - if (_collection[temp] == null) + bool pushed = false; + for (int index = position + 1; index < Count; index++) { - _collection[temp] = obj; - return true; + if (_collection[index] == null) + { + position = index; + pushed = true; + break; + } } - temp++; - } - temp = position - 1; - while (temp > 0) - { - if (_collection[temp] == null) + if (!pushed) { - _collection[temp] = obj; - return true; + for (int index = position - 1; index >= 0; index--) + { + if (_collection[index] == null) + { + position = index; + pushed = true; + break; + } + } + } + + if (!pushed) + { + return position; } - temp--; } - return false; + _collection[position] = obj; + return position; } - public bool Remove(int position) + public T? Remove(int position) { if (position < 0 || position >= Count) - return false; + { + return null; + } + if (_collection[position] == null) return null; + + T? temp = _collection[position]; _collection[position] = null; - - return true; + return temp; } } } \ No newline at end of file diff --git a/ProjectLiner/ProjectLiner/FormLinerCollection.cs b/ProjectLiner/ProjectLiner/FormLinerCollection.cs index 56b4370..3e759f4 100644 --- a/ProjectLiner/ProjectLiner/FormLinerCollection.cs +++ b/ProjectLiner/ProjectLiner/FormLinerCollection.cs @@ -63,7 +63,7 @@ namespace ProjectLiner return; } - if (_company + drawingLiner) + if (_company + drawingLiner != -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _company.Show(); @@ -123,7 +123,7 @@ namespace ProjectLiner } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_company - pos) + if (_company - pos != null) { MessageBox.Show("Объект удален"); pictureBox.Image = _company.Show();