From 46fb3ca9d8d4a45b6fb3af952fdd72673efc8319 Mon Sep 17 00:00:00 2001
From: sqdselo <147947144+sqdselo@users.noreply.github.com>
Date: Thu, 4 Apr 2024 15:14:16 +0400
Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D1=8E?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../AbstractCompany.cs | 4 +--
.../ICollectionGenericObjects.cs | 4 +--
.../ListGenericObjects.cs | 25 +++++++++++++------
.../MassivGenericObjects.cs | 20 +++++++--------
.../HoistingCrane/FormCarCollection.cs | 2 +-
5 files changed, 33 insertions(+), 22 deletions(-)
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
index b6b8cd6..7ed15c5 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs
@@ -42,9 +42,9 @@ namespace HoistingCrane.CollectionGenericObjects
arr.SetMaxCount = GetMaxCount;
}
- public static DrawningTrackedVehicle operator +(AbstractCompany company, DrawningTrackedVehicle car)
+ public static int operator +(AbstractCompany company, DrawningTrackedVehicle car)
{
- return company.arr?.Insert(car) ?? null;
+ return company.arr?.Insert(car) ?? -1;
}
public static DrawningTrackedVehicle operator -(AbstractCompany company, int position)
{
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs
index 679548b..adc295a 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -17,14 +17,14 @@ namespace HoistingCrane.CollectionGenericObjects
///
///
///
- T? Insert(T obj);
+ int Insert(T obj);
///
/// Добавление элемента в коллекцию на определенную позицию
///
///
///
///
- T? Insert(T obj, int position);
+ int Insert(T obj, int position);
///
/// Удаление элемента из коллекции по его позиции
///
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs
index ba05f0a..3af71fa 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs
@@ -39,7 +39,7 @@ namespace HoistingCrane.CollectionGenericObjects
public T? Get(int position)
{
// TODO проверка позиции
- if(position >= 0 && position < list.Count)
+ if(position >= 0 && position < _maxCount)
{
return list[position];
}
@@ -47,7 +47,7 @@ namespace HoistingCrane.CollectionGenericObjects
}
- public T? Insert(T obj)
+ public int Insert(T obj)
{
// TODO проверка, что не превышено максимальное количество элементов
// TODO вставка в конец набора
@@ -55,23 +55,34 @@ namespace HoistingCrane.CollectionGenericObjects
{
return Insert(obj, 0);
}
- return null;
+ return -1;
}
- public T? Insert(T obj, int position)
+ public int Insert(T obj, int position)
{
// TODO проверка, что не превышено максимальное количество элементов
// TODO проверка позиции
// TODO вставка по позиции
- if(position >= 0 && position < list.Count)
+ if(position >= 0 && position < _maxCount)
{
if (list[position] == null)
{
list.Add(obj);
- return list[position];
+ return position;
+ }
+ else
+ {
+ if (Insert(obj, position + 1) != -1)
+ {
+ return position;
+ }
+ if (Insert(obj, position - 1) != -1)
+ {
+ return position;
+ }
}
}
- return null;
+ return -1;
}
diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs
index bd5beca..ef399d3 100644
--- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs
+++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs
@@ -31,7 +31,7 @@ namespace HoistingCrane.CollectionGenericObjects
return null;
}
- public T? Insert(T obj)
+ public int Insert(T obj)
{
for (int i = 0; i < Count; i++)
{
@@ -40,34 +40,34 @@ namespace HoistingCrane.CollectionGenericObjects
return Insert(obj, 0);
}
}
- return null;
+ return -1;
}
- public T? Insert(T obj, int position)
+ public int Insert(T obj, int position)
{
//todo Проверка позиции
if (position < 0 || position > Count)
{
- return null;
+ return -1;
}
if (arr[position] == null)
{
arr[position] = obj;
- return arr[position];
+ return position;
}
else
{
- if (Insert(obj, position + 1) != null)
+ if (Insert(obj, position + 1) != -1)
{
- return arr[position + 1];
+ return position;
}
- if (Insert(obj, position - 1) != null)
+ if (Insert(obj, position - 1) != -1)
{
- return arr[position - 1];
+ return position;
}
}
- return null;
+ return -1;
}
public T? Remove(int position)
diff --git a/HoistingCrane/HoistingCrane/FormCarCollection.cs b/HoistingCrane/HoistingCrane/FormCarCollection.cs
index 4d1678b..3dc984a 100644
--- a/HoistingCrane/HoistingCrane/FormCarCollection.cs
+++ b/HoistingCrane/HoistingCrane/FormCarCollection.cs
@@ -52,7 +52,7 @@ namespace HoistingCrane
default:
return;
}
- if ((_company + drawning) != null)
+ if ((_company + drawning) != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show();