From a14763fff526380b87c14c7c426cc6e75a9d2229 Mon Sep 17 00:00:00 2001 From: ValAnn Date: Fri, 13 Oct 2023 11:12:32 +0400 Subject: [PATCH] result +- --- DumpTruck/DumpTruck/CarsGenericCollection.cs | 10 +++++----- DumpTruck/DumpTruck/SetGeneric.cs | 12 +++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/DumpTruck/DumpTruck/CarsGenericCollection.cs b/DumpTruck/DumpTruck/CarsGenericCollection.cs index 9f2388c..5b79fe6 100644 --- a/DumpTruck/DumpTruck/CarsGenericCollection.cs +++ b/DumpTruck/DumpTruck/CarsGenericCollection.cs @@ -52,14 +52,14 @@ namespace DumpTruck.Generics /// /// /// - public static T? operator +(CarsGenericCollection collect, T? + public static int operator +(CarsGenericCollection collect, T? obj) { if (obj == null) { - return null; + return -1; } - return collect?._collection.Insert(obj) ?? null; + return collect._collection.Insert(obj); } /// /// Перегрузка оператора вычитания @@ -67,7 +67,7 @@ namespace DumpTruck.Generics /// /// /// - public static T? operator -(CarsGenericCollection collect, int + public static bool operator -(CarsGenericCollection collect, int pos) { T? obj = collect._collection.Get(pos); @@ -75,7 +75,7 @@ namespace DumpTruck.Generics { collect._collection.Remove(pos); } - return obj; + return true; } /// /// Получение объекта IMoveableObject diff --git a/DumpTruck/DumpTruck/SetGeneric.cs b/DumpTruck/DumpTruck/SetGeneric.cs index 974765c..c76f900 100644 --- a/DumpTruck/DumpTruck/SetGeneric.cs +++ b/DumpTruck/DumpTruck/SetGeneric.cs @@ -3,11 +3,13 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Forms.VisualStyles; namespace DumpTruck.Generics { internal class SetGeneric where T : class + { /// /// Массив объектов, которые храним @@ -32,10 +34,10 @@ namespace DumpTruck.Generics /// /// Добавляемый автомобиль /// - public T? Insert(T car) + public int Insert(T car) { if (_places[Count - 1] != null) - return null; + return -1; return Insert(car, 0); } /// @@ -44,10 +46,10 @@ namespace DumpTruck.Generics /// Добавляемый автомобиль /// Позиция /// - public T? Insert(T car, int position) + public int Insert(T car, int position) { if (!(position >= 0 && position < Count)) - return null; + return -1; if (_places[position] != null) { int indexEnd = position + 1; @@ -62,7 +64,7 @@ namespace DumpTruck.Generics } _places[position] = car; - return car; + return position; } // TODO проверка, что элемент массива по этой позиции пустой, если нет, то // проверка, что после вставляемого элемента в массиве есть пустой элемент