.
This commit is contained in:
parent
bc62abb2b5
commit
0628d80e97
@ -1,25 +0,0 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
|
||||||
# Visual Studio Version 17
|
|
||||||
VisualStudioVersion = 17.8.34330.188
|
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BinarySearch", "BinarySearch\BinarySearch.csproj", "{D32DE24F-D9A3-411A-91C6-142A6FA1B7CF}"
|
|
||||||
EndProject
|
|
||||||
Global
|
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
|
||||||
Debug|Any CPU = Debug|Any CPU
|
|
||||||
Release|Any CPU = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
|
||||||
{D32DE24F-D9A3-411A-91C6-142A6FA1B7CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{D32DE24F-D9A3-411A-91C6-142A6FA1B7CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{D32DE24F-D9A3-411A-91C6-142A6FA1B7CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{D32DE24F-D9A3-411A-91C6-142A6FA1B7CF}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
|
||||||
HideSolutionNode = FALSE
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
|
||||||
SolutionGuid = {6D9191C7-467F-4DA5-A5FB-D9795C6A8B77}
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
|
@ -1,26 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<OutputType>WinExe</OutputType>
|
|
||||||
<TargetFramework>net7.0-windows</TargetFramework>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
<UseWindowsForms>true</UseWindowsForms>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Compile Update="Properties\Resources.Designer.cs">
|
|
||||||
<DesignTime>True</DesignTime>
|
|
||||||
<AutoGen>True</AutoGen>
|
|
||||||
<DependentUpon>Resources.resx</DependentUpon>
|
|
||||||
</Compile>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<EmbeddedResource Update="Properties\Resources.resx">
|
|
||||||
<Generator>ResXFileCodeGenerator</Generator>
|
|
||||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
|
||||||
</EmbeddedResource>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
@ -1,17 +0,0 @@
|
|||||||
namespace BinarySearch
|
|
||||||
{
|
|
||||||
internal static class Program
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The main entry point for the application.
|
|
||||||
/// </summary>
|
|
||||||
[STAThread]
|
|
||||||
static void Main()
|
|
||||||
{
|
|
||||||
// To customize application configuration such as set high DPI settings or default font,
|
|
||||||
// see https://aka.ms/applicationconfiguration.
|
|
||||||
ApplicationConfiguration.Initialize();
|
|
||||||
Application.Run(new MainForm());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,63 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
// <auto-generated>
|
|
||||||
// Этот код создан программой.
|
|
||||||
// Исполняемая версия:4.0.30319.42000
|
|
||||||
//
|
|
||||||
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
|
|
||||||
// повторной генерации кода.
|
|
||||||
// </auto-generated>
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
namespace BinarySearch.Properties {
|
|
||||||
using System;
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
|
|
||||||
/// </summary>
|
|
||||||
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
|
|
||||||
// с помощью такого средства, как ResGen или Visual Studio.
|
|
||||||
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
|
|
||||||
// с параметром /str или перестройте свой проект VS.
|
|
||||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
|
||||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
|
||||||
internal class Resources {
|
|
||||||
|
|
||||||
private static global::System.Resources.ResourceManager resourceMan;
|
|
||||||
|
|
||||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
|
||||||
|
|
||||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
|
||||||
internal Resources() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
|
|
||||||
/// </summary>
|
|
||||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
|
||||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
|
||||||
get {
|
|
||||||
if (object.ReferenceEquals(resourceMan, null)) {
|
|
||||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("BinarySearch.Properties.Resources", typeof(Resources).Assembly);
|
|
||||||
resourceMan = temp;
|
|
||||||
}
|
|
||||||
return resourceMan;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
|
|
||||||
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
|
|
||||||
/// </summary>
|
|
||||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
|
||||||
internal static global::System.Globalization.CultureInfo Culture {
|
|
||||||
get {
|
|
||||||
return resourceCulture;
|
|
||||||
}
|
|
||||||
set {
|
|
||||||
resourceCulture = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,120 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<root>
|
|
||||||
<!--
|
|
||||||
Microsoft ResX Schema
|
|
||||||
|
|
||||||
Version 2.0
|
|
||||||
|
|
||||||
The primary goals of this format is to allow a simple XML format
|
|
||||||
that is mostly human readable. The generation and parsing of the
|
|
||||||
various data types are done through the TypeConverter classes
|
|
||||||
associated with the data types.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
... ado.net/XML headers & schema ...
|
|
||||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
|
||||||
<resheader name="version">2.0</resheader>
|
|
||||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
|
||||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
|
||||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
|
||||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
|
||||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
|
||||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
|
||||||
</data>
|
|
||||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
|
||||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
|
||||||
<comment>This is a comment</comment>
|
|
||||||
</data>
|
|
||||||
|
|
||||||
There are any number of "resheader" rows that contain simple
|
|
||||||
name/value pairs.
|
|
||||||
|
|
||||||
Each data row contains a name, and value. The row also contains a
|
|
||||||
type or mimetype. Type corresponds to a .NET class that support
|
|
||||||
text/value conversion through the TypeConverter architecture.
|
|
||||||
Classes that don't support this are serialized and stored with the
|
|
||||||
mimetype set.
|
|
||||||
|
|
||||||
The mimetype is used for serialized objects, and tells the
|
|
||||||
ResXResourceReader how to depersist the object. This is currently not
|
|
||||||
extensible. For a given mimetype the value must be set accordingly:
|
|
||||||
|
|
||||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
|
||||||
that the ResXResourceWriter will generate, however the reader can
|
|
||||||
read any of the formats listed below.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.binary.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.soap.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
|
||||||
value : The object must be serialized into a byte array
|
|
||||||
: using a System.ComponentModel.TypeConverter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
-->
|
|
||||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
|
||||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
|
||||||
<xsd:element name="root" msdata:IsDataSet="true">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:choice maxOccurs="unbounded">
|
|
||||||
<xsd:element name="metadata">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
|
||||||
<xsd:attribute name="type" type="xsd:string" />
|
|
||||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
|
||||||
<xsd:attribute ref="xml:space" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="assembly">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:attribute name="alias" type="xsd:string" />
|
|
||||||
<xsd:attribute name="name" type="xsd:string" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="data">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
|
||||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
|
||||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
|
||||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
|
||||||
<xsd:attribute ref="xml:space" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="resheader">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
</xsd:choice>
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
</xsd:schema>
|
|
||||||
<resheader name="resmimetype">
|
|
||||||
<value>text/microsoft-resx</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="version">
|
|
||||||
<value>2.0</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="reader">
|
|
||||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="writer">
|
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
|
||||||
</resheader>
|
|
||||||
</root>
|
|
@ -1,22 +0,0 @@
|
|||||||
namespace BinarySearch.State;
|
|
||||||
|
|
||||||
[Serializable]
|
|
||||||
public class SearchState
|
|
||||||
{
|
|
||||||
public int Left { get; }
|
|
||||||
public int Right { get; }
|
|
||||||
public int Mid { get; }
|
|
||||||
public List<int> array { get; }
|
|
||||||
public int target { get; }
|
|
||||||
public bool IsExist { get; }
|
|
||||||
|
|
||||||
public SearchState(int left, int right, int mid, bool isExist, List<int> array, int target)
|
|
||||||
{
|
|
||||||
Left = left;
|
|
||||||
Right = right;
|
|
||||||
Mid = mid;
|
|
||||||
IsExist = isExist;
|
|
||||||
this.array = array;
|
|
||||||
this.target = target;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,101 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Runtime.Serialization.Formatters.Binary;
|
|
||||||
|
|
||||||
namespace BinarySearch.State;
|
|
||||||
|
|
||||||
public class StateStorage
|
|
||||||
{
|
|
||||||
private List<SearchState> states;
|
|
||||||
private int currentIndex;
|
|
||||||
|
|
||||||
public StateStorage()
|
|
||||||
{
|
|
||||||
states = new List<SearchState>();
|
|
||||||
currentIndex = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddState(SearchState state)
|
|
||||||
{
|
|
||||||
states.Add(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Clear()
|
|
||||||
{
|
|
||||||
states.Clear();
|
|
||||||
currentIndex = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Reset()
|
|
||||||
{
|
|
||||||
currentIndex = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SearchState? GetNextState()
|
|
||||||
{
|
|
||||||
currentIndex++;
|
|
||||||
if (currentIndex < states.Count)
|
|
||||||
{
|
|
||||||
return states[currentIndex];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public SearchState? GetPreviousState()
|
|
||||||
{
|
|
||||||
currentIndex--;
|
|
||||||
if (currentIndex >= 0 && currentIndex < states.Count)
|
|
||||||
{
|
|
||||||
return states[currentIndex];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsTraversalComplete()
|
|
||||||
{
|
|
||||||
return currentIndex >= states.Count - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool SaveToFile(string filename)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
BinaryFormatter formatter = new BinaryFormatter();
|
|
||||||
using FileStream fs = new FileStream(filename, FileMode.Create);
|
|
||||||
#pragma warning disable SYSLIB0011
|
|
||||||
formatter.Serialize(fs, states);
|
|
||||||
#pragma warning restore SYSLIB0011
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Error saving file: {ex.Message}");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool LoadFromFile(string filename)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
BinaryFormatter formatter = new BinaryFormatter();
|
|
||||||
using FileStream fs = new FileStream(filename, FileMode.Open);
|
|
||||||
#pragma warning disable SYSLIB0011
|
|
||||||
states = (List<SearchState>)formatter.Deserialize(fs);
|
|
||||||
#pragma warning restore SYSLIB0011
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Error loading file: {ex.Message}");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,73 +0,0 @@
|
|||||||
namespace BinarySearch.Algorithm;
|
|
||||||
|
|
||||||
public class BinarySearchRunner
|
|
||||||
{
|
|
||||||
private List<int> sortedArray;
|
|
||||||
private int target;
|
|
||||||
private int left { get; set; }
|
|
||||||
private int right { get; set; }
|
|
||||||
private int mid { get; set; }
|
|
||||||
private int? targetIndex { get; set; }
|
|
||||||
|
|
||||||
public BinarySearchRunner(List<int> array, int target)
|
|
||||||
{
|
|
||||||
targetIndex = null;
|
|
||||||
sortedArray = array;
|
|
||||||
this.target = target;
|
|
||||||
left = 0;
|
|
||||||
right = array.Count - 1;
|
|
||||||
mid = left + (right - left) / 2;
|
|
||||||
SortArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SortArray()
|
|
||||||
{
|
|
||||||
sortedArray.Sort();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ExecuteStep()
|
|
||||||
{
|
|
||||||
if (left <= right)
|
|
||||||
{
|
|
||||||
if (sortedArray[mid] == target)
|
|
||||||
{
|
|
||||||
targetIndex = mid;
|
|
||||||
left = mid + 1;
|
|
||||||
right = mid - 1;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (left == right)
|
|
||||||
{
|
|
||||||
targetIndex = -1;
|
|
||||||
left = mid + 1;
|
|
||||||
right = mid - 1;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (sortedArray[mid] < target)
|
|
||||||
{
|
|
||||||
left = mid + 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
right = mid - 1;
|
|
||||||
}
|
|
||||||
mid = left + (right - left) / 2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
targetIndex = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Condition CreateState()
|
|
||||||
{
|
|
||||||
return new Condition(left, right, mid, targetIndex, sortedArray, target);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsOver()
|
|
||||||
{
|
|
||||||
return left <= right;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
|||||||
namespace BinarySearch.Algorithm;
|
|
||||||
|
|
||||||
[Serializable]
|
|
||||||
public class Condition
|
|
||||||
{
|
|
||||||
public int Left { get; }
|
|
||||||
public int Right { get; }
|
|
||||||
public int Mid { get; }
|
|
||||||
public List<int> Array { get; }
|
|
||||||
public int Target { get; }
|
|
||||||
public int? TargetIndex { get; }
|
|
||||||
|
|
||||||
public Condition(int left, int right, int mid, int? targetIndex, List<int> array, int target)
|
|
||||||
{
|
|
||||||
Left = left;
|
|
||||||
Right = right;
|
|
||||||
Mid = mid;
|
|
||||||
TargetIndex = targetIndex;
|
|
||||||
Array = array;
|
|
||||||
Target = target;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,133 +0,0 @@
|
|||||||
using System.Runtime.Serialization.Formatters.Binary;
|
|
||||||
using System.Text.Json;
|
|
||||||
|
|
||||||
namespace BinarySearch.Algorithm;
|
|
||||||
|
|
||||||
public class ConditionStorage
|
|
||||||
{
|
|
||||||
private List<Condition> states;
|
|
||||||
private int currentIndex;
|
|
||||||
|
|
||||||
public ConditionStorage()
|
|
||||||
{
|
|
||||||
states = new List<Condition>();
|
|
||||||
currentIndex = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddState(Condition state)
|
|
||||||
{
|
|
||||||
states.Add(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Clear()
|
|
||||||
{
|
|
||||||
states.Clear();
|
|
||||||
currentIndex = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Reset()
|
|
||||||
{
|
|
||||||
currentIndex = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Condition? GetNextState()
|
|
||||||
{
|
|
||||||
if (currentIndex + 1 < states.Count)
|
|
||||||
{
|
|
||||||
currentIndex++;
|
|
||||||
return states[currentIndex];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Condition? GetPreviousState()
|
|
||||||
{
|
|
||||||
if (currentIndex > 0 && currentIndex < states.Count)
|
|
||||||
{
|
|
||||||
currentIndex--;
|
|
||||||
return states[currentIndex];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool SaveToFile(string filename)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
string extension = Path.GetExtension(filename).ToLower();
|
|
||||||
|
|
||||||
if (extension == ".bin")
|
|
||||||
{
|
|
||||||
// Сохранение в бинарный формат
|
|
||||||
BinaryFormatter formatter = new BinaryFormatter();
|
|
||||||
using FileStream fs = new FileStream(filename, FileMode.Create);
|
|
||||||
#pragma warning disable SYSLIB0011
|
|
||||||
formatter.Serialize(fs, states);
|
|
||||||
#pragma warning restore SYSLIB0011
|
|
||||||
}
|
|
||||||
else if (extension == ".json")
|
|
||||||
{
|
|
||||||
// Сохранение в формат JSON
|
|
||||||
string json = JsonSerializer.Serialize(states);
|
|
||||||
File.WriteAllText(filename, json);
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Неподдерживаемое расширение файла
|
|
||||||
Console.WriteLine("Unsupported file extension");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Error saving file: {ex.Message}");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool LoadFromFile(string filename)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
string extension = Path.GetExtension(filename).ToLower();
|
|
||||||
|
|
||||||
if (extension == ".bin")
|
|
||||||
{
|
|
||||||
// Загрузка из бинарного файла
|
|
||||||
BinaryFormatter formatter = new BinaryFormatter();
|
|
||||||
using FileStream fs = new FileStream(filename, FileMode.Open);
|
|
||||||
#pragma warning disable SYSLIB0011
|
|
||||||
states = (List<Condition>)formatter.Deserialize(fs);
|
|
||||||
#pragma warning restore SYSLIB0011
|
|
||||||
}
|
|
||||||
else if (extension == ".json")
|
|
||||||
{
|
|
||||||
// Загрузка из файла в формате JSON
|
|
||||||
string json = File.ReadAllText(filename);
|
|
||||||
states = JsonSerializer.Deserialize<List<Condition>>(json);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Неподдерживаемое расширение файла
|
|
||||||
Console.WriteLine("Unsupported file extension");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Error loading file: {ex.Message}");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
namespace BinarySearch.Algorithm;
|
|
||||||
|
|
||||||
public class Manager
|
|
||||||
{
|
|
||||||
private readonly ConditionStorage _storage;
|
|
||||||
|
|
||||||
public Manager(ConditionStorage storage)
|
|
||||||
{
|
|
||||||
_storage = storage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ExecuteBinarySearch(Parameters parameters)
|
|
||||||
{
|
|
||||||
if (parameters == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(parameters));
|
|
||||||
}
|
|
||||||
BinarySearchRunner algorithm = new(parameters.Array, parameters.Target);
|
|
||||||
Condition? state;
|
|
||||||
_storage.Clear();
|
|
||||||
|
|
||||||
while (algorithm.IsOver())
|
|
||||||
{
|
|
||||||
state = algorithm.CreateState();
|
|
||||||
_storage.AddState(state);
|
|
||||||
algorithm.ExecuteStep();
|
|
||||||
}
|
|
||||||
state = algorithm.CreateState();
|
|
||||||
_storage.AddState(state);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
namespace BinarySearch.Algorithm;
|
|
||||||
|
|
||||||
public class Parameters
|
|
||||||
{
|
|
||||||
public List<int>? Array { get; }
|
|
||||||
public int Target { get; }
|
|
||||||
|
|
||||||
public Parameters()
|
|
||||||
{
|
|
||||||
Array = new List<int>();
|
|
||||||
Target = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Parameters(List<int>? array, int target)
|
|
||||||
{
|
|
||||||
Array = array;
|
|
||||||
if (Array != null)
|
|
||||||
{
|
|
||||||
Array.Sort();
|
|
||||||
}
|
|
||||||
Target = target;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,106 +0,0 @@
|
|||||||
namespace BinarySearch.Algorithm;
|
|
||||||
|
|
||||||
public class Visualizer
|
|
||||||
{
|
|
||||||
private readonly MainForm _mainForm;
|
|
||||||
private readonly List<int> _array;
|
|
||||||
|
|
||||||
public Visualizer(MainForm mainForm, List<int> array)
|
|
||||||
{
|
|
||||||
_mainForm = mainForm;
|
|
||||||
_array = array;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Visualize(Condition state)
|
|
||||||
{
|
|
||||||
Color color;
|
|
||||||
if (state.TargetIndex == null)
|
|
||||||
{
|
|
||||||
color = Color.Pink;
|
|
||||||
} else if (state.TargetIndex >= 0)
|
|
||||||
{
|
|
||||||
color = Color.LimeGreen;
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
color = Color.IndianRed;
|
|
||||||
}
|
|
||||||
UpdatePanelByStep(state, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdatePanel()
|
|
||||||
{
|
|
||||||
_mainForm.flowLayoutPanelArray.Controls.Clear();
|
|
||||||
_mainForm.flowLayoutPanelIndex.Controls.Clear();
|
|
||||||
|
|
||||||
if (_array != null)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < _array.Count; i++)
|
|
||||||
{
|
|
||||||
TextBox textBox = new()
|
|
||||||
{
|
|
||||||
Text = _array[i].ToString(),
|
|
||||||
Width = 40,
|
|
||||||
ReadOnly = false
|
|
||||||
};
|
|
||||||
|
|
||||||
TextBox textBoxIndex = new()
|
|
||||||
{
|
|
||||||
Text = i.ToString(),
|
|
||||||
Width = 40,
|
|
||||||
ReadOnly = true,
|
|
||||||
Enabled = false
|
|
||||||
};
|
|
||||||
|
|
||||||
_mainForm.flowLayoutPanelArray.Controls.Add(textBox);
|
|
||||||
_mainForm.flowLayoutPanelIndex.Controls.Add(textBoxIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdatePanelByStep(Condition state, Color color)
|
|
||||||
{
|
|
||||||
_mainForm.flowLayoutPanelArray.Controls.Clear();
|
|
||||||
_mainForm.flowLayoutPanelIndex.Controls.Clear();
|
|
||||||
if (state.Mid < state.Target)
|
|
||||||
{
|
|
||||||
_mainForm.labelMid.Text = "";
|
|
||||||
}
|
|
||||||
if (_array != null)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < _array.Count; i++)
|
|
||||||
{
|
|
||||||
TextBox textBox = new()
|
|
||||||
{
|
|
||||||
Text = _array[i].ToString(),
|
|
||||||
Width = 40,
|
|
||||||
ReadOnly = true
|
|
||||||
};
|
|
||||||
|
|
||||||
if ((i < state.Left || i > state.Right) && i != state.Mid)
|
|
||||||
{
|
|
||||||
textBox.BackColor = Color.Black;
|
|
||||||
textBox.ForeColor = Color.White;
|
|
||||||
textBox.Enabled = false;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (i == state.Mid)
|
|
||||||
{
|
|
||||||
textBox.BackColor = color;
|
|
||||||
textBox.ForeColor = Color.White;
|
|
||||||
textBox.Enabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
TextBox textBoxIndex = new()
|
|
||||||
{
|
|
||||||
Text = i.ToString(),
|
|
||||||
Width = 40,
|
|
||||||
ReadOnly = true,
|
|
||||||
Enabled = false
|
|
||||||
};
|
|
||||||
|
|
||||||
_mainForm.flowLayoutPanelArray.Controls.Add(textBox);
|
|
||||||
_mainForm.flowLayoutPanelIndex.Controls.Add(textBoxIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
156
BinarySearch/BinarySearch/forms/AddArrayForm.Designer.cs
generated
156
BinarySearch/BinarySearch/forms/AddArrayForm.Designer.cs
generated
@ -1,156 +0,0 @@
|
|||||||
namespace BinarySearch
|
|
||||||
{
|
|
||||||
partial class AddArrayForm
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Required designer variable.
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clean up any resources being used.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing && (components != null))
|
|
||||||
{
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Required method for Designer support - do not modify
|
|
||||||
/// the contents of this method with the code editor.
|
|
||||||
/// </summary>
|
|
||||||
private void InitializeComponent()
|
|
||||||
{
|
|
||||||
numericUpDownSearchNumber = new NumericUpDown();
|
|
||||||
labelAdd = new Label();
|
|
||||||
buttonAdd = new Button();
|
|
||||||
buttonSave = new Button();
|
|
||||||
listBoxArray = new ListBox();
|
|
||||||
label1 = new Label();
|
|
||||||
numericUpDownAddNumber = new NumericUpDown();
|
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDownSearchNumber).BeginInit();
|
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDownAddNumber).BeginInit();
|
|
||||||
SuspendLayout();
|
|
||||||
//
|
|
||||||
// numericUpDownSearchNumber
|
|
||||||
//
|
|
||||||
numericUpDownSearchNumber.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
|
||||||
numericUpDownSearchNumber.Location = new Point(530, 63);
|
|
||||||
numericUpDownSearchNumber.Margin = new Padding(4);
|
|
||||||
numericUpDownSearchNumber.Maximum = new decimal(new int[] { 101, 0, 0, 0 });
|
|
||||||
numericUpDownSearchNumber.Minimum = new decimal(new int[] { 101, 0, 0, int.MinValue });
|
|
||||||
numericUpDownSearchNumber.Name = "numericUpDownSearchNumber";
|
|
||||||
numericUpDownSearchNumber.Size = new Size(92, 26);
|
|
||||||
numericUpDownSearchNumber.TabIndex = 0;
|
|
||||||
//
|
|
||||||
// labelAdd
|
|
||||||
//
|
|
||||||
labelAdd.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
|
||||||
labelAdd.AutoSize = true;
|
|
||||||
labelAdd.Font = new Font("Montserrat", 10.8F, FontStyle.Regular, GraphicsUnit.Point);
|
|
||||||
labelAdd.Location = new Point(355, 65);
|
|
||||||
labelAdd.Margin = new Padding(4, 0, 4, 0);
|
|
||||||
labelAdd.Name = "labelAdd";
|
|
||||||
labelAdd.Size = new Size(155, 25);
|
|
||||||
labelAdd.TabIndex = 1;
|
|
||||||
labelAdd.Text = "искомое число:";
|
|
||||||
//
|
|
||||||
// buttonAdd
|
|
||||||
//
|
|
||||||
buttonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
|
||||||
buttonAdd.Location = new Point(355, 111);
|
|
||||||
buttonAdd.Margin = new Padding(4);
|
|
||||||
buttonAdd.Name = "buttonAdd";
|
|
||||||
buttonAdd.Size = new Size(268, 33);
|
|
||||||
buttonAdd.TabIndex = 2;
|
|
||||||
buttonAdd.Text = "добавить";
|
|
||||||
buttonAdd.UseVisualStyleBackColor = true;
|
|
||||||
buttonAdd.Click += buttonAdd_Click;
|
|
||||||
//
|
|
||||||
// buttonSave
|
|
||||||
//
|
|
||||||
buttonSave.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
|
||||||
buttonSave.Location = new Point(355, 152);
|
|
||||||
buttonSave.Margin = new Padding(4);
|
|
||||||
buttonSave.Name = "buttonSave";
|
|
||||||
buttonSave.Size = new Size(268, 33);
|
|
||||||
buttonSave.TabIndex = 3;
|
|
||||||
buttonSave.Text = "сохранить";
|
|
||||||
buttonSave.UseVisualStyleBackColor = true;
|
|
||||||
buttonSave.Click += buttonSave_Click;
|
|
||||||
//
|
|
||||||
// listBoxArray
|
|
||||||
//
|
|
||||||
listBoxArray.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
|
||||||
listBoxArray.FormattingEnabled = true;
|
|
||||||
listBoxArray.ItemHeight = 21;
|
|
||||||
listBoxArray.Items.AddRange(new object[] { "" });
|
|
||||||
listBoxArray.Location = new Point(18, 18);
|
|
||||||
listBoxArray.Margin = new Padding(4);
|
|
||||||
listBoxArray.Name = "listBoxArray";
|
|
||||||
listBoxArray.Size = new Size(280, 151);
|
|
||||||
listBoxArray.TabIndex = 4;
|
|
||||||
//
|
|
||||||
// label1
|
|
||||||
//
|
|
||||||
label1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
|
||||||
label1.AutoSize = true;
|
|
||||||
label1.Location = new Point(18, 182);
|
|
||||||
label1.Margin = new Padding(4, 0, 4, 0);
|
|
||||||
label1.Name = "label1";
|
|
||||||
label1.Size = new Size(144, 21);
|
|
||||||
label1.TabIndex = 6;
|
|
||||||
label1.Text = "элемент массива";
|
|
||||||
//
|
|
||||||
// numericUpDownAddNumber
|
|
||||||
//
|
|
||||||
numericUpDownAddNumber.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
|
||||||
numericUpDownAddNumber.Location = new Point(196, 180);
|
|
||||||
numericUpDownAddNumber.Margin = new Padding(4);
|
|
||||||
numericUpDownAddNumber.Maximum = new decimal(new int[] { 101, 0, 0, 0 });
|
|
||||||
numericUpDownAddNumber.Minimum = new decimal(new int[] { 101, 0, 0, int.MinValue });
|
|
||||||
numericUpDownAddNumber.Name = "numericUpDownAddNumber";
|
|
||||||
numericUpDownAddNumber.Size = new Size(102, 26);
|
|
||||||
numericUpDownAddNumber.TabIndex = 5;
|
|
||||||
//
|
|
||||||
// AddArrayForm
|
|
||||||
//
|
|
||||||
AutoScaleDimensions = new SizeF(10F, 21F);
|
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
|
||||||
BackColor = Color.LightSkyBlue;
|
|
||||||
ClientSize = new Size(655, 224);
|
|
||||||
Controls.Add(label1);
|
|
||||||
Controls.Add(numericUpDownAddNumber);
|
|
||||||
Controls.Add(listBoxArray);
|
|
||||||
Controls.Add(buttonSave);
|
|
||||||
Controls.Add(buttonAdd);
|
|
||||||
Controls.Add(labelAdd);
|
|
||||||
Controls.Add(numericUpDownSearchNumber);
|
|
||||||
Font = new Font("Montserrat", 9F, FontStyle.Regular, GraphicsUnit.Point);
|
|
||||||
Margin = new Padding(4);
|
|
||||||
Name = "AddArrayForm";
|
|
||||||
Text = "заполнение массива";
|
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDownSearchNumber).EndInit();
|
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDownAddNumber).EndInit();
|
|
||||||
ResumeLayout(false);
|
|
||||||
PerformLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private NumericUpDown numericUpDownSearchNumber;
|
|
||||||
private Label labelAdd;
|
|
||||||
private Button buttonAdd;
|
|
||||||
private Button buttonSave;
|
|
||||||
private ListBox listBoxArray;
|
|
||||||
private Label label1;
|
|
||||||
private NumericUpDown numericUpDownAddNumber;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
using BinarySearch.Algorithm;
|
|
||||||
namespace BinarySearch;
|
|
||||||
|
|
||||||
public partial class AddArrayForm : Form
|
|
||||||
{
|
|
||||||
public delegate void InitParametersDelegate(Parameters searchParameters);
|
|
||||||
|
|
||||||
public event InitParametersDelegate? InitParametersEvent;
|
|
||||||
|
|
||||||
private List<int> _array;
|
|
||||||
|
|
||||||
public AddArrayForm()
|
|
||||||
{
|
|
||||||
_array = new List<int>();
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateListBox()
|
|
||||||
{
|
|
||||||
listBoxArray.Items.Clear();
|
|
||||||
foreach (int number in _array)
|
|
||||||
{
|
|
||||||
listBoxArray.Items.Add(number);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void buttonAdd_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
AddNumber((int)numericUpDownAddNumber.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void AddNumber(int number)
|
|
||||||
{
|
|
||||||
_array.Add(number);
|
|
||||||
UpdateListBox();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void buttonSave_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
Parameters parameters = new Parameters(_array, (int)numericUpDownSearchNumber.Value);
|
|
||||||
InitParametersEvent?.Invoke(parameters);
|
|
||||||
|
|
||||||
this.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,120 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<root>
|
|
||||||
<!--
|
|
||||||
Microsoft ResX Schema
|
|
||||||
|
|
||||||
Version 2.0
|
|
||||||
|
|
||||||
The primary goals of this format is to allow a simple XML format
|
|
||||||
that is mostly human readable. The generation and parsing of the
|
|
||||||
various data types are done through the TypeConverter classes
|
|
||||||
associated with the data types.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
... ado.net/XML headers & schema ...
|
|
||||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
|
||||||
<resheader name="version">2.0</resheader>
|
|
||||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
|
||||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
|
||||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
|
||||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
|
||||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
|
||||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
|
||||||
</data>
|
|
||||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
|
||||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
|
||||||
<comment>This is a comment</comment>
|
|
||||||
</data>
|
|
||||||
|
|
||||||
There are any number of "resheader" rows that contain simple
|
|
||||||
name/value pairs.
|
|
||||||
|
|
||||||
Each data row contains a name, and value. The row also contains a
|
|
||||||
type or mimetype. Type corresponds to a .NET class that support
|
|
||||||
text/value conversion through the TypeConverter architecture.
|
|
||||||
Classes that don't support this are serialized and stored with the
|
|
||||||
mimetype set.
|
|
||||||
|
|
||||||
The mimetype is used for serialized objects, and tells the
|
|
||||||
ResXResourceReader how to depersist the object. This is currently not
|
|
||||||
extensible. For a given mimetype the value must be set accordingly:
|
|
||||||
|
|
||||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
|
||||||
that the ResXResourceWriter will generate, however the reader can
|
|
||||||
read any of the formats listed below.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.binary.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.soap.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
|
||||||
value : The object must be serialized into a byte array
|
|
||||||
: using a System.ComponentModel.TypeConverter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
-->
|
|
||||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
|
||||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
|
||||||
<xsd:element name="root" msdata:IsDataSet="true">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:choice maxOccurs="unbounded">
|
|
||||||
<xsd:element name="metadata">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
|
||||||
<xsd:attribute name="type" type="xsd:string" />
|
|
||||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
|
||||||
<xsd:attribute ref="xml:space" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="assembly">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:attribute name="alias" type="xsd:string" />
|
|
||||||
<xsd:attribute name="name" type="xsd:string" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="data">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
|
||||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
|
||||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
|
||||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
|
||||||
<xsd:attribute ref="xml:space" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="resheader">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
</xsd:choice>
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
</xsd:schema>
|
|
||||||
<resheader name="resmimetype">
|
|
||||||
<value>text/microsoft-resx</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="version">
|
|
||||||
<value>2.0</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="reader">
|
|
||||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="writer">
|
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
|
||||||
</resheader>
|
|
||||||
</root>
|
|
64
BinarySearch/BinarySearch/forms/InfoForm.Designer.cs
generated
64
BinarySearch/BinarySearch/forms/InfoForm.Designer.cs
generated
@ -1,64 +0,0 @@
|
|||||||
namespace BinarySearch
|
|
||||||
{
|
|
||||||
partial class InfoForm
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Required designer variable.
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clean up any resources being used.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing && (components != null))
|
|
||||||
{
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Required method for Designer support - do not modify
|
|
||||||
/// the contents of this method with the code editor.
|
|
||||||
/// </summary>
|
|
||||||
private void InitializeComponent()
|
|
||||||
{
|
|
||||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(InfoForm));
|
|
||||||
richTextBox1 = new RichTextBox();
|
|
||||||
fontDialog1 = new FontDialog();
|
|
||||||
SuspendLayout();
|
|
||||||
//
|
|
||||||
// richTextBox1
|
|
||||||
//
|
|
||||||
richTextBox1.Font = new Font("Montserrat", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
|
||||||
richTextBox1.Location = new Point(13, 13);
|
|
||||||
richTextBox1.Margin = new Padding(4);
|
|
||||||
richTextBox1.Name = "richTextBox1";
|
|
||||||
richTextBox1.Size = new Size(1014, 708);
|
|
||||||
richTextBox1.TabIndex = 0;
|
|
||||||
richTextBox1.Text = resources.GetString("richTextBox1.Text");
|
|
||||||
//
|
|
||||||
// InfoForm
|
|
||||||
//
|
|
||||||
AutoScaleDimensions = new SizeF(11F, 28F);
|
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
|
||||||
BackColor = Color.DarkSlateBlue;
|
|
||||||
ClientSize = new Size(1040, 734);
|
|
||||||
Controls.Add(richTextBox1);
|
|
||||||
Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
|
||||||
Margin = new Padding(4);
|
|
||||||
Name = "InfoForm";
|
|
||||||
Text = "информация об алгоритме";
|
|
||||||
ResumeLayout(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
private RichTextBox richTextBox1;
|
|
||||||
private FontDialog fontDialog1;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Data;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace BinarySearch
|
|
||||||
{
|
|
||||||
public partial class InfoForm : Form
|
|
||||||
{
|
|
||||||
public InfoForm()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,153 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<root>
|
|
||||||
<!--
|
|
||||||
Microsoft ResX Schema
|
|
||||||
|
|
||||||
Version 2.0
|
|
||||||
|
|
||||||
The primary goals of this format is to allow a simple XML format
|
|
||||||
that is mostly human readable. The generation and parsing of the
|
|
||||||
various data types are done through the TypeConverter classes
|
|
||||||
associated with the data types.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
... ado.net/XML headers & schema ...
|
|
||||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
|
||||||
<resheader name="version">2.0</resheader>
|
|
||||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
|
||||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
|
||||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
|
||||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
|
||||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
|
||||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
|
||||||
</data>
|
|
||||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
|
||||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
|
||||||
<comment>This is a comment</comment>
|
|
||||||
</data>
|
|
||||||
|
|
||||||
There are any number of "resheader" rows that contain simple
|
|
||||||
name/value pairs.
|
|
||||||
|
|
||||||
Each data row contains a name, and value. The row also contains a
|
|
||||||
type or mimetype. Type corresponds to a .NET class that support
|
|
||||||
text/value conversion through the TypeConverter architecture.
|
|
||||||
Classes that don't support this are serialized and stored with the
|
|
||||||
mimetype set.
|
|
||||||
|
|
||||||
The mimetype is used for serialized objects, and tells the
|
|
||||||
ResXResourceReader how to depersist the object. This is currently not
|
|
||||||
extensible. For a given mimetype the value must be set accordingly:
|
|
||||||
|
|
||||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
|
||||||
that the ResXResourceWriter will generate, however the reader can
|
|
||||||
read any of the formats listed below.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.binary.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.soap.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
|
||||||
value : The object must be serialized into a byte array
|
|
||||||
: using a System.ComponentModel.TypeConverter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
-->
|
|
||||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
|
||||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
|
||||||
<xsd:element name="root" msdata:IsDataSet="true">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:choice maxOccurs="unbounded">
|
|
||||||
<xsd:element name="metadata">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
|
||||||
<xsd:attribute name="type" type="xsd:string" />
|
|
||||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
|
||||||
<xsd:attribute ref="xml:space" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="assembly">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:attribute name="alias" type="xsd:string" />
|
|
||||||
<xsd:attribute name="name" type="xsd:string" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="data">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
|
||||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
|
||||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
|
||||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
|
||||||
<xsd:attribute ref="xml:space" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="resheader">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
</xsd:choice>
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
</xsd:schema>
|
|
||||||
<resheader name="resmimetype">
|
|
||||||
<value>text/microsoft-resx</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="version">
|
|
||||||
<value>2.0</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="reader">
|
|
||||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="writer">
|
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
|
||||||
</resheader>
|
|
||||||
<data name="richTextBox1.Text" xml:space="preserve">
|
|
||||||
<value>Алгоритм бинарного поиска - это эффективный алгоритм поиска элемента в упорядоченном массиве или списке. Он работает следующим образом:
|
|
||||||
|
|
||||||
1. Определяем начало и конец массива (начальный и конечный индексы).
|
|
||||||
2. Вычисляем середину массива, как среднее между началом и концом.
|
|
||||||
3. Сравниваем искомый элемент с элементом в середине массива.
|
|
||||||
- Если они равны, значит мы нашли искомый элемент и алгоритм завершается.
|
|
||||||
- Если искомый элемент меньше, чем элемент в середине, то ищем в левой половине массива (от начала до середины).
|
|
||||||
- Если искомый элемент больше, чем элемент в середине, то ищем в правой половине массива (от середины до конца).
|
|
||||||
4. Повторяем шаги 2 и 3, пока не найдем искомый элемент или пока не сузим диапазон поиска до 1 элемента.
|
|
||||||
|
|
||||||
Преимущества бинарного поиска:
|
|
||||||
- Время работы алгоритма имеет логарифмическую сложность O(log n), что делает его очень эффективным для больших массивов.
|
|
||||||
- Алгоритм работает только с упорядоченными массивами, что позволяет быстро находить элементы.
|
|
||||||
|
|
||||||
Недостатки бинарного поиска:
|
|
||||||
- Массив должен быть предварительно отсортирован, что требует дополнительных временных и вычислительных ресурсов.
|
|
||||||
- Алгоритм не может работать с неупорядоченными массивами.
|
|
||||||
|
|
||||||
Бинарный поиск широко применяется в различных областях, таких как поиск в базах данных, в компьютерных алгоритмах, при решении задач с большими объемами информации.
|
|
||||||
1. После запуска приложения пользователю доступны опции ввода массива, загрузки/сохранения файла, а также пошаговое отслеживание хода алгоритма.
|
|
||||||
|
|
||||||
2. Нажав кнопку "Об алгоритме" в правой части формы, пользователь может ознакомиться с информацией об алгоритме бинарного поиска и принципах его работы.
|
|
||||||
|
|
||||||
3. После ввода массива пользователь нажимает кнопку "Начать бинарный поиск" в правой части формы, чтобы запустить алгоритм.
|
|
||||||
|
|
||||||
4. В нижнем левом углу находятся кнопки, которые позволяют пользователю пошагово наблюдать за ходом выполнения алгоритма бинарного поиска.
|
|
||||||
|
|
||||||
</value>
|
|
||||||
</data>
|
|
||||||
<metadata name="fontDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
|
||||||
<value>17, 17</value>
|
|
||||||
</metadata>
|
|
||||||
</root>
|
|
260
BinarySearch/BinarySearch/forms/MainForm.Designer.cs
generated
260
BinarySearch/BinarySearch/forms/MainForm.Designer.cs
generated
@ -1,260 +0,0 @@
|
|||||||
using System.Linq.Expressions;
|
|
||||||
|
|
||||||
namespace BinarySearch
|
|
||||||
{
|
|
||||||
partial class MainForm
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Required designer variable.
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clean up any resources being used.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing && (components != null))
|
|
||||||
{
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Required method for Designer support - do not modify
|
|
||||||
/// the contents of this method with the code editor.
|
|
||||||
/// </summary>
|
|
||||||
private void InitializeComponent()
|
|
||||||
{
|
|
||||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
|
|
||||||
groupBoxTarget = new GroupBox();
|
|
||||||
labelTarget = new Label();
|
|
||||||
buttonStart = new Button();
|
|
||||||
buttonInfo = new Button();
|
|
||||||
buttonAddData = new Button();
|
|
||||||
buttonStepBack = new Button();
|
|
||||||
buttonStepForward = new Button();
|
|
||||||
flowLayoutPanelArray = new FlowLayoutPanel();
|
|
||||||
flowLayoutPanelIndex = new FlowLayoutPanel();
|
|
||||||
menuStrip1 = new MenuStrip();
|
|
||||||
файлToolStripMenuItem = new ToolStripMenuItem();
|
|
||||||
toolStripMenuItemSave = new ToolStripMenuItem();
|
|
||||||
toolStripMenuItemLoad = new ToolStripMenuItem();
|
|
||||||
saveFileDialog = new SaveFileDialog();
|
|
||||||
openFileDialog = new OpenFileDialog();
|
|
||||||
labelMid = new Label();
|
|
||||||
groupBoxTarget.SuspendLayout();
|
|
||||||
menuStrip1.SuspendLayout();
|
|
||||||
SuspendLayout();
|
|
||||||
//
|
|
||||||
// groupBoxTarget
|
|
||||||
//
|
|
||||||
groupBoxTarget.BackColor = Color.SeaShell;
|
|
||||||
groupBoxTarget.Controls.Add(labelTarget);
|
|
||||||
groupBoxTarget.Location = new Point(14, 42);
|
|
||||||
groupBoxTarget.Margin = new Padding(3, 4, 3, 4);
|
|
||||||
groupBoxTarget.Name = "groupBoxTarget";
|
|
||||||
groupBoxTarget.Padding = new Padding(3, 4, 3, 4);
|
|
||||||
groupBoxTarget.Size = new Size(236, 76);
|
|
||||||
groupBoxTarget.TabIndex = 12;
|
|
||||||
groupBoxTarget.TabStop = false;
|
|
||||||
groupBoxTarget.Text = "требуемое число";
|
|
||||||
//
|
|
||||||
// labelTarget
|
|
||||||
//
|
|
||||||
labelTarget.AutoSize = true;
|
|
||||||
labelTarget.Location = new Point(20, 29);
|
|
||||||
labelTarget.Name = "labelTarget";
|
|
||||||
labelTarget.Size = new Size(13, 18);
|
|
||||||
labelTarget.TabIndex = 5;
|
|
||||||
labelTarget.Text = "-";
|
|
||||||
//
|
|
||||||
// buttonStart
|
|
||||||
//
|
|
||||||
buttonStart.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
|
||||||
buttonStart.Location = new Point(243, 150);
|
|
||||||
buttonStart.Margin = new Padding(3, 4, 3, 4);
|
|
||||||
buttonStart.Name = "buttonStart";
|
|
||||||
buttonStart.Size = new Size(236, 28);
|
|
||||||
buttonStart.TabIndex = 3;
|
|
||||||
buttonStart.Text = "начать бинарный поиск";
|
|
||||||
buttonStart.UseVisualStyleBackColor = true;
|
|
||||||
buttonStart.Click += buttonStart_Click;
|
|
||||||
//
|
|
||||||
// buttonInfo
|
|
||||||
//
|
|
||||||
buttonInfo.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
|
||||||
buttonInfo.Location = new Point(1060, 150);
|
|
||||||
buttonInfo.Margin = new Padding(3, 4, 3, 4);
|
|
||||||
buttonInfo.Name = "buttonInfo";
|
|
||||||
buttonInfo.Size = new Size(164, 28);
|
|
||||||
buttonInfo.TabIndex = 1;
|
|
||||||
buttonInfo.Text = "о приложении";
|
|
||||||
buttonInfo.UseVisualStyleBackColor = true;
|
|
||||||
buttonInfo.Click += buttonInfo_Click;
|
|
||||||
//
|
|
||||||
// buttonAddData
|
|
||||||
//
|
|
||||||
buttonAddData.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
|
||||||
buttonAddData.Location = new Point(16, 150);
|
|
||||||
buttonAddData.Margin = new Padding(3, 4, 3, 4);
|
|
||||||
buttonAddData.Name = "buttonAddData";
|
|
||||||
buttonAddData.Size = new Size(202, 28);
|
|
||||||
buttonAddData.TabIndex = 0;
|
|
||||||
buttonAddData.Text = "добавить данные";
|
|
||||||
buttonAddData.UseVisualStyleBackColor = true;
|
|
||||||
buttonAddData.Click += buttonAddData_Click;
|
|
||||||
//
|
|
||||||
// buttonStepBack
|
|
||||||
//
|
|
||||||
buttonStepBack.Anchor = AnchorStyles.Left;
|
|
||||||
buttonStepBack.Location = new Point(731, 154);
|
|
||||||
buttonStepBack.Margin = new Padding(3, 4, 3, 4);
|
|
||||||
buttonStepBack.Name = "buttonStepBack";
|
|
||||||
buttonStepBack.Size = new Size(84, 28);
|
|
||||||
buttonStepBack.TabIndex = 4;
|
|
||||||
buttonStepBack.Text = "назад";
|
|
||||||
buttonStepBack.UseVisualStyleBackColor = true;
|
|
||||||
buttonStepBack.Click += buttonStepBack_Click;
|
|
||||||
//
|
|
||||||
// buttonStepForward
|
|
||||||
//
|
|
||||||
buttonStepForward.Anchor = AnchorStyles.None;
|
|
||||||
buttonStepForward.Location = new Point(822, 154);
|
|
||||||
buttonStepForward.Margin = new Padding(3, 4, 3, 4);
|
|
||||||
buttonStepForward.Name = "buttonStepForward";
|
|
||||||
buttonStepForward.Size = new Size(84, 28);
|
|
||||||
buttonStepForward.TabIndex = 2;
|
|
||||||
buttonStepForward.Text = "вперед";
|
|
||||||
buttonStepForward.UseVisualStyleBackColor = true;
|
|
||||||
buttonStepForward.Click += buttonStepForward_Click;
|
|
||||||
//
|
|
||||||
// flowLayoutPanelArray
|
|
||||||
//
|
|
||||||
flowLayoutPanelArray.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
|
||||||
flowLayoutPanelArray.BackColor = Color.Transparent;
|
|
||||||
flowLayoutPanelArray.Location = new Point(267, 90);
|
|
||||||
flowLayoutPanelArray.Margin = new Padding(3, 4, 3, 4);
|
|
||||||
flowLayoutPanelArray.Name = "flowLayoutPanelArray";
|
|
||||||
flowLayoutPanelArray.Size = new Size(958, 43);
|
|
||||||
flowLayoutPanelArray.TabIndex = 3;
|
|
||||||
//
|
|
||||||
// flowLayoutPanelIndex
|
|
||||||
//
|
|
||||||
flowLayoutPanelIndex.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
|
||||||
flowLayoutPanelIndex.BackColor = Color.Transparent;
|
|
||||||
flowLayoutPanelIndex.Location = new Point(267, 42);
|
|
||||||
flowLayoutPanelIndex.Margin = new Padding(3, 4, 3, 4);
|
|
||||||
flowLayoutPanelIndex.Name = "flowLayoutPanelIndex";
|
|
||||||
flowLayoutPanelIndex.Size = new Size(958, 43);
|
|
||||||
flowLayoutPanelIndex.TabIndex = 4;
|
|
||||||
//
|
|
||||||
// menuStrip1
|
|
||||||
//
|
|
||||||
menuStrip1.ImageScalingSize = new Size(20, 20);
|
|
||||||
menuStrip1.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
|
|
||||||
menuStrip1.Location = new Point(0, 0);
|
|
||||||
menuStrip1.Name = "menuStrip1";
|
|
||||||
menuStrip1.Padding = new Padding(7, 3, 0, 3);
|
|
||||||
menuStrip1.Size = new Size(1239, 30);
|
|
||||||
menuStrip1.TabIndex = 6;
|
|
||||||
menuStrip1.Text = "menuStrip1";
|
|
||||||
//
|
|
||||||
// файлToolStripMenuItem
|
|
||||||
//
|
|
||||||
файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { toolStripMenuItemSave, toolStripMenuItemLoad });
|
|
||||||
файлToolStripMenuItem.Name = "файлToolStripMenuItem";
|
|
||||||
файлToolStripMenuItem.Size = new Size(58, 24);
|
|
||||||
файлToolStripMenuItem.Text = "файл";
|
|
||||||
//
|
|
||||||
// toolStripMenuItemSave
|
|
||||||
//
|
|
||||||
toolStripMenuItemSave.Enabled = false;
|
|
||||||
toolStripMenuItemSave.Name = "toolStripMenuItemSave";
|
|
||||||
toolStripMenuItemSave.ShortcutKeys = Keys.Control | Keys.S;
|
|
||||||
toolStripMenuItemSave.Size = new Size(171, 26);
|
|
||||||
toolStripMenuItemSave.Text = "save";
|
|
||||||
toolStripMenuItemSave.Click += toolStripMenuItemSave_Click;
|
|
||||||
//
|
|
||||||
// toolStripMenuItemLoad
|
|
||||||
//
|
|
||||||
toolStripMenuItemLoad.Name = "toolStripMenuItemLoad";
|
|
||||||
toolStripMenuItemLoad.ShortcutKeys = Keys.Control | Keys.L;
|
|
||||||
toolStripMenuItemLoad.Size = new Size(171, 26);
|
|
||||||
toolStripMenuItemLoad.Text = "load";
|
|
||||||
toolStripMenuItemLoad.Click += toolStripMenuItemLoad_Click;
|
|
||||||
//
|
|
||||||
// saveFileDialog
|
|
||||||
//
|
|
||||||
saveFileDialog.Filter = "bin file (*.bin)|*.bin|json file (*.json)|*.json";
|
|
||||||
//
|
|
||||||
// openFileDialog
|
|
||||||
//
|
|
||||||
openFileDialog.Filter = "All files (*.bin, *.json)|*.bin;*.json|Binary files (*.bin)|*.bin|JSON files (*.json)|*.json";
|
|
||||||
//
|
|
||||||
// labelMid
|
|
||||||
//
|
|
||||||
labelMid.AutoSize = true;
|
|
||||||
labelMid.Location = new Point(16, 168);
|
|
||||||
labelMid.Name = "labelMid";
|
|
||||||
labelMid.Size = new Size(0, 18);
|
|
||||||
labelMid.TabIndex = 7;
|
|
||||||
//
|
|
||||||
// MainForm
|
|
||||||
//
|
|
||||||
AutoScaleDimensions = new SizeF(9F, 18F);
|
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
|
||||||
BackColor = Color.PeachPuff;
|
|
||||||
BackgroundImage = (Image)resources.GetObject("$this.BackgroundImage");
|
|
||||||
ClientSize = new Size(1239, 201);
|
|
||||||
Controls.Add(groupBoxTarget);
|
|
||||||
Controls.Add(labelMid);
|
|
||||||
Controls.Add(buttonStart);
|
|
||||||
Controls.Add(buttonStepBack);
|
|
||||||
Controls.Add(buttonAddData);
|
|
||||||
Controls.Add(buttonInfo);
|
|
||||||
Controls.Add(flowLayoutPanelIndex);
|
|
||||||
Controls.Add(flowLayoutPanelArray);
|
|
||||||
Controls.Add(buttonStepForward);
|
|
||||||
Controls.Add(menuStrip1);
|
|
||||||
Font = new Font("Montserrat SemiBold", 7.79999971F, FontStyle.Bold, GraphicsUnit.Point);
|
|
||||||
Icon = (Icon)resources.GetObject("$this.Icon");
|
|
||||||
MainMenuStrip = menuStrip1;
|
|
||||||
Margin = new Padding(3, 4, 3, 4);
|
|
||||||
Name = "MainForm";
|
|
||||||
Text = "бинарный поиск";
|
|
||||||
groupBoxTarget.ResumeLayout(false);
|
|
||||||
groupBoxTarget.PerformLayout();
|
|
||||||
menuStrip1.ResumeLayout(false);
|
|
||||||
menuStrip1.PerformLayout();
|
|
||||||
ResumeLayout(false);
|
|
||||||
PerformLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private GroupBox groupBoxTools;
|
|
||||||
private Button buttonInfo;
|
|
||||||
private Button buttonAddData;
|
|
||||||
private Button buttonStepForward;
|
|
||||||
private Button buttonStart;
|
|
||||||
public FlowLayoutPanel flowLayoutPanelArray;
|
|
||||||
private Label labelTarget;
|
|
||||||
public FlowLayoutPanel flowLayoutPanelIndex;
|
|
||||||
private MenuStrip menuStrip1;
|
|
||||||
private ToolStripMenuItem файлToolStripMenuItem;
|
|
||||||
private ToolStripMenuItem toolStripMenuItemSave;
|
|
||||||
private ToolStripMenuItem toolStripMenuItemLoad;
|
|
||||||
private SaveFileDialog saveFileDialog;
|
|
||||||
private OpenFileDialog openFileDialog;
|
|
||||||
public Label labelMid;
|
|
||||||
private Button buttonStepBack;
|
|
||||||
private ProgressBar progressBarSteps;
|
|
||||||
private GroupBox groupBox2;
|
|
||||||
private GroupBox groupBoxTarget;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,134 +0,0 @@
|
|||||||
using BinarySearch.Algorithm;
|
|
||||||
|
|
||||||
namespace BinarySearch;
|
|
||||||
|
|
||||||
public partial class MainForm : Form
|
|
||||||
{
|
|
||||||
private readonly ConditionStorage _stateStorage;
|
|
||||||
private readonly Manager _manager;
|
|
||||||
private Parameters _parameters;
|
|
||||||
private Visualizer _visualizer;
|
|
||||||
|
|
||||||
public MainForm()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
_stateStorage = new ConditionStorage();
|
|
||||||
_manager = new Manager(_stateStorage);
|
|
||||||
_parameters = new Parameters();
|
|
||||||
_visualizer = new Visualizer(this, _parameters.Array);
|
|
||||||
buttonStepForward.Enabled = false;
|
|
||||||
buttonStepBack.Enabled = false;
|
|
||||||
buttonStart.Enabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void buttonAddData_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
AddArrayForm initDataForm = new();
|
|
||||||
initDataForm.InitParametersEvent += InitParametersEventHandler;
|
|
||||||
initDataForm.ShowDialog();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void InitParametersEventHandler(Parameters searchParameters)
|
|
||||||
{
|
|
||||||
_parameters = new Parameters(searchParameters.Array, searchParameters.Target);
|
|
||||||
_visualizer = new Visualizer(this, _parameters.Array);
|
|
||||||
_visualizer.UpdatePanel();
|
|
||||||
labelTarget.Text = searchParameters.Target.ToString();
|
|
||||||
buttonStart.Enabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void buttonStart_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
_stateStorage.Reset();
|
|
||||||
_visualizer.UpdatePanel();
|
|
||||||
_manager.ExecuteBinarySearch(_parameters);
|
|
||||||
toolStripMenuItemSave.Enabled = true;
|
|
||||||
buttonStepForward.Enabled = true;
|
|
||||||
buttonStepBack.Enabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void buttonStepForward_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
Condition? searchState = _stateStorage.GetNextState();
|
|
||||||
Condition? searchStateCheck = _stateStorage.GetNextState();
|
|
||||||
if (searchStateCheck == null && searchState != null)
|
|
||||||
{
|
|
||||||
buttonStepForward.Enabled = false;
|
|
||||||
if (searchState.TargetIndex != null && searchState.TargetIndex >= 0)
|
|
||||||
{
|
|
||||||
MessageBox.Show($"число {searchState.Target} найдено с индексом {searchState.TargetIndex}", "итог", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
||||||
} else if (searchState.TargetIndex != null && searchState.TargetIndex < 0)
|
|
||||||
{
|
|
||||||
MessageBox.Show($"число {searchState.Target} не найдено", "итог", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
_visualizer.Visualize(searchState);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
searchState = _stateStorage.GetPreviousState();
|
|
||||||
if (searchState == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_visualizer.Visualize(searchState);
|
|
||||||
buttonStepForward.Enabled = true;
|
|
||||||
buttonStepBack.Enabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void buttonStepBack_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
Condition? searchState = _stateStorage.GetPreviousState();
|
|
||||||
if (searchState == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_visualizer.Visualize(searchState);
|
|
||||||
buttonStepForward.Enabled = true;
|
|
||||||
buttonStepBack.Enabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void buttonInfo_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
InfoForm infoForm = new();
|
|
||||||
infoForm.ShowDialog();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void toolStripMenuItemSave_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
|
||||||
{
|
|
||||||
if (_stateStorage.SaveToFile(saveFileDialog.FileName))
|
|
||||||
{
|
|
||||||
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void toolStripMenuItemLoad_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
|
||||||
{
|
|
||||||
if (_stateStorage.LoadFromFile(openFileDialog.FileName))
|
|
||||||
{
|
|
||||||
Condition? state = _stateStorage.GetNextState();
|
|
||||||
if (state != null)
|
|
||||||
{
|
|
||||||
_parameters = new Parameters(state.Array, state.Target);
|
|
||||||
_visualizer = new Visualizer(this, _parameters.Array);
|
|
||||||
_visualizer.UpdatePanel();
|
|
||||||
labelTarget.Text = state.Target.ToString();
|
|
||||||
_stateStorage.GetPreviousState();
|
|
||||||
}
|
|
||||||
buttonStart.Enabled = true;
|
|
||||||
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user