Skip to content

Commit

Permalink
Добавьте файлы проекта.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan authored and ivan committed May 12, 2024
1 parent 142b3e2 commit d365e9a
Show file tree
Hide file tree
Showing 11 changed files with 914 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Lab_12_1.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34024.191
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lab_12_1", "Lab_12_1\Lab_12_1.csproj", "{8653E681-31C0-4537-9309-CDFCA13C6D99}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestProject322", "TestProject322\TestProject322.csproj", "{97069E5A-D43E-4E79-A5D0-7660CF7C944D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClassLibrary", "..\Labb_10\MusicalInstrument\ClassLibrary.csproj", "{073A6CA5-DA0F-404B-8C02-4CE78ABDF0A6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8653E681-31C0-4537-9309-CDFCA13C6D99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8653E681-31C0-4537-9309-CDFCA13C6D99}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8653E681-31C0-4537-9309-CDFCA13C6D99}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8653E681-31C0-4537-9309-CDFCA13C6D99}.Release|Any CPU.Build.0 = Release|Any CPU
{97069E5A-D43E-4E79-A5D0-7660CF7C944D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{97069E5A-D43E-4E79-A5D0-7660CF7C944D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{97069E5A-D43E-4E79-A5D0-7660CF7C944D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{97069E5A-D43E-4E79-A5D0-7660CF7C944D}.Release|Any CPU.Build.0 = Release|Any CPU
{073A6CA5-DA0F-404B-8C02-4CE78ABDF0A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{073A6CA5-DA0F-404B-8C02-4CE78ABDF0A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{073A6CA5-DA0F-404B-8C02-4CE78ABDF0A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{073A6CA5-DA0F-404B-8C02-4CE78ABDF0A6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EBDF0207-E7DE-437A-9E0A-9816E4564E43}
EndGlobalSection
EndGlobal
58 changes: 58 additions & 0 deletions Lab_12_1/ClassDiagram1.cd
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<ClassDiagram MajorVersion="1" MinorVersion="1">
<Class Name="Lab_12_1.MyList&lt;T&gt;">
<Position X="12.75" Y="2.75" Width="1.5" />
<TypeIdentifier>
<HashCode>ACABAAACAAAABAAABAAAAgQEAAAAEAAUBAEAAAAQAAA=</HashCode>
<FileName>MyList.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="Lab_12_1.Point&lt;T&gt;">
<Position X="5" Y="1" Width="1.5" />
<TypeIdentifier>
<HashCode>AgAAAAAAAAAAAAAEAAAAAAAAAAAAAJAAEAAAAAAAAAA=</HashCode>
<FileName>Point.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="Lab_12_1.Program">
<Position X="10.25" Y="2.75" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAA=</HashCode>
<FileName>Program.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="ClassLibrary.ElectricGuitar">
<Position X="6.25" Y="6.25" Width="1.5" />
<TypeIdentifier />
</Class>
<Class Name="ClassLibrary.Guitar">
<Position X="10.75" Y="6.25" Width="1.5" />
<TypeIdentifier />
</Class>
<Class Name="ClassLibrary.ICM">
<Position X="10.25" Y="1" Width="1.5" />
<TypeIdentifier />
</Class>
<Class Name="ClassLibrary.IdNumber">
<Position X="6.75" Y="1" Width="1.5" />
<TypeIdentifier />
</Class>
<Class Name="ClassLibrary.MusicalInstrument">
<Position X="8.5" Y="1" Width="1.5" />
<TypeIdentifier />
<Lollipop Position="0.2" />
</Class>
<Class Name="ClassLibrary.Piano">
<Position X="8.5" Y="6.25" Width="1.5" />
<TypeIdentifier />
</Class>
<Class Name="ClassLibrary.SBTL">
<Position X="12" Y="1" Width="1.5" />
<TypeIdentifier />
</Class>
<Interface Name="ClassLibrary.IInit">
<Position X="13.75" Y="1" Width="1.5" />
<TypeIdentifier />
</Interface>
<Font Name="Segoe UI" Size="9" />
</ClassDiagram>
14 changes: 14 additions & 0 deletions Lab_12_1/Lab_12_1.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Labb_10\MusicalInstrument\ClassLibrary.csproj" />
</ItemGroup>

</Project>
234 changes: 234 additions & 0 deletions Lab_12_1/MyList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Drawing;
using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.Runtime.Serialization.Json;
using System.Security;
using System.Text;
using System.Threading.Tasks;
using ClassLibrary;
using static System.Net.Mime.MediaTypeNames;
namespace Lab_12_1
{
public class MyList<T> where T: IInit, ICloneable, new()
{
public Point<T>? beg = null;
public Point<T>? end = null;

int count = 0;

public int Count => count; // свойство для чтения

public Point<T> MakeRandomData() // случайный элемент типа Т
{
T data = new T();
data.RandomInit();
return new Point<T>(data);
}

public T MakeRandomItem() // случайное информационное поле
{
T data = new T();
data.RandomInit();
return data;
}

public void AddToBegin(T item) // добавление в начало
{
T newData = (T)item.Clone(); //глубокое копирование
Point<T> newItem = new Point<T>(newData);
count++;
if (beg != null)
{
beg.Pred = newItem;
newItem.Next = beg;
beg = newItem;
}
else
{
beg = newItem;
end = beg;
}
}

public void AddToEnd(T item) //добавление в конец
{
T newData = (T)item.Clone(); //глубокое копирование
Point<T> newItem = new Point<T>(newData);
count++;
if (end != null)
{
end.Next = newItem;
newItem.Pred = end;
end = newItem;
}
else
{
beg = newItem;
end = beg;
}
}

public MyList() { } // конструктор без параметров

public MyList(int size) // конструктор с параметром 'размер'
{
if (size <= 0) throw new Exception("size less zero");
beg = MakeRandomData();
end = beg;
for (int i = 1; i < size; i++)
{
T newItem = MakeRandomItem();
AddToEnd(newItem);
}
}

public MyList(T[] collection) // способ задать несколько элементов в виде массива
{
if (collection == null) throw new Exception("empty collection: null");
if (collection.Length == 0) throw new Exception("empty collection");
T newData = (T)collection[0].Clone();
beg = new Point<T>(newData);
end = beg;
for (int i = 1; i < collection.Length; i++)
{
AddToEnd(collection[i]);
}
}

public void PrintList() // печать списка
{
if (count == 0) Console.WriteLine("this list is empty");
Point<T>? current = beg;
for (int i = 0; current != null; i++)
{
Console.WriteLine(current);
current = current.Next;
}
}

public Point<T>? FindItem(T item) //поиск элемента
{
Point<T>? current = beg;
while (current != null)
{
if (current.Data == null)
{
throw new Exception("Data is null");
}
if (current.Data.Equals(item))
{
return current;
}
current = current.Next;
}
return null;
}

public bool RemoveItem(T item) // удаление элемента
{
if (beg == null) throw new Exception("the empty list");
Point<T>? pos = FindItem(item);
if (pos == null) return false;
count--;
// один элемент
if (beg == end)
{
beg = end = null;
return true;
}
// первый элемент
if (pos.Pred == null)
{
beg = beg?.Next;
beg.Pred = null;
return true;
}
// последний элемент
if (pos.Next == null)
{
end = end.Pred;
end.Next = null;
return true;
}
// для остальных случаев
Point<T> next = pos.Next;
Point<T> pred = pos.Pred;
pos.Next.Pred = pred;
pos.Pred.Next = next;
return true;
}

public void RemoveItem2(T item) // Удаление элемента с полем и всех последующих
{
if (beg == null) throw new Exception("the empty list");
Point<T>? tek = beg;
while (tek != null)
{
if (tek.Data != null && tek.Data.Equals(item))
{
if (tek.Next != null) tek.Next.Pred = null; // Удаление текущего элемента и всех последующих
end = tek.Pred;
end.Next = null;
count--;
break;
}
tek = tek.Next; // Переходим к следующему элементу
}
}

public MyList<T> CloneList() // глубокое копирование
{
MyList<T> clone = new();
if (beg == null) return clone;
Point<T>? current = beg;
while (current != null)
{
clone.AddToEnd(current.Data);
current = current.Next;
}
return clone;
}

public void ClearList() // удалить список из памяти
{
Point<T>? current = beg;
while (current != null)
{
current.Pred = null;
current = current.Next;
}
beg = null;
end = null;
count = 0;
}

public void AddByPlace() // добавить случайные элементы на места нечётных элементов
{
if (beg == null) throw new Exception("Список пуст.");
Point<T>? current = beg;
int index = 1;
while (current != null)
{
if (index % 2 != 0)
{
// Создаем новый элемент
T newData = new();
newData.RandomInit();
Point<T> newPoint = new(newData);
// Добавляем новый элемент после текущего
newPoint.Next = current.Next;
if (current.Next != null) current.Next.Pred = newPoint;
current.Next = newPoint;
newPoint.Pred = current;
count++;
}
// Переходим к следующему элементу
current = current.Next;
index++;
}
}
}
}
40 changes: 40 additions & 0 deletions Lab_12_1/Point.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;

namespace Lab_12_1
{
public class Point<T>
{
public T? Data { get; set; }
public Point<T>? Next { get; set; }
public Point<T>? Pred { get; set; }

public Point()
{
this.Data = default(T);
this.Pred = null;
this.Next = null;
}

public Point(T data)
{
this.Data = data;
this.Pred = null;
this.Next = null;
}

public override string ToString()
{
return Data == null ? "": Data.ToString();
}

public override int GetHashCode()
{
return Data == null ? 0: Data.GetHashCode();
}
}
}
Loading

0 comments on commit d365e9a

Please sign in to comment.