Добавлена сортировка массивов
This commit is contained in:
parent
f7342093af
commit
0fc0fdb125
@ -11,6 +11,7 @@ class Program
|
||||
static AboutMeForm aboutMeForm;
|
||||
static MathGameForm mathGameForm;
|
||||
static SnakeForm snakeForm;
|
||||
static ArraySortGUI arrayGUI;
|
||||
|
||||
[STAThread] // Требуется для Windows Forms
|
||||
static void Main()
|
||||
@ -35,7 +36,7 @@ class Program
|
||||
Menu mainMenu = new Menu("Select option");
|
||||
mainMenu.AddOption("Guess answer math game", () => mainMenuForm.SwitchToForm(mathGameForm));
|
||||
mainMenu.AddOption("About me", () => mainMenuForm.SwitchToForm(aboutMeForm));
|
||||
mainMenu.AddOption("Array sort", () => new ArraySortDemo().Run());
|
||||
mainMenu.AddOption("Array sort", () => { arrayGUI = new ArraySortGUI(mainMenuForm); mainMenuForm.SwitchToForm(arrayGUI); });
|
||||
mainMenu.AddOption("Snake game", () => {
|
||||
mainMenuForm.Hide();
|
||||
snakeDiffMenuForm.Show();
|
||||
|
@ -139,6 +139,15 @@ namespace laba3.Core
|
||||
Console.WriteLine("\b\b]");
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string str = "[";
|
||||
foreach (int x in this.array) { str+=$"{x}, "; }
|
||||
str = str.TrimEnd(' ').TrimEnd(',');
|
||||
str += "]";
|
||||
return str;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sort this array with Gnome Sort;
|
||||
/// Avg time O(n^2);
|
||||
|
39
GUI/ArraySortGUI.Designer.cs
generated
Normal file
39
GUI/ArraySortGUI.Designer.cs
generated
Normal file
@ -0,0 +1,39 @@
|
||||
namespace ProgLab1.GUI
|
||||
{
|
||||
partial class ArraySortGUI
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Text = "ArraySortGUI";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
116
GUI/ArraySortGUI.cs
Normal file
116
GUI/ArraySortGUI.cs
Normal file
@ -0,0 +1,116 @@
|
||||
using laba3.Core;
|
||||
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 ProgLab1.GUI
|
||||
{
|
||||
public partial class ArraySortGUI : Form
|
||||
{
|
||||
private long time1;
|
||||
private long time2;
|
||||
private Label lblArraySize;
|
||||
private TextBox txtArraySize;
|
||||
private Button btnRun;
|
||||
private TextBox txtOutput;
|
||||
|
||||
public ArraySortGUI(Form onCloseForm)
|
||||
{
|
||||
// Initialize components
|
||||
lblArraySize = new Label
|
||||
{
|
||||
Location = new System.Drawing.Point(12, 12),
|
||||
Name = "lblArraySize",
|
||||
Size = new System.Drawing.Size(100, 22),
|
||||
Text = "Размер массива:"
|
||||
};
|
||||
|
||||
txtArraySize = new TextBox
|
||||
{
|
||||
Location = new System.Drawing.Point(150, 12),
|
||||
Name = "txtArraySize",
|
||||
Size = new System.Drawing.Size(150, 22),
|
||||
PlaceholderText = "Размер массива"
|
||||
};
|
||||
|
||||
btnRun = new Button
|
||||
{
|
||||
Location = new System.Drawing.Point(310, 10),
|
||||
Name = "btnRun",
|
||||
Size = new System.Drawing.Size(100, 25),
|
||||
Text = "Запустить",
|
||||
UseVisualStyleBackColor = true
|
||||
};
|
||||
btnRun.Click += new EventHandler(this.btnRun_Click);
|
||||
|
||||
txtOutput = new TextBox
|
||||
{
|
||||
Location = new System.Drawing.Point(12, 50),
|
||||
Multiline = true,
|
||||
Name = "txtOutput",
|
||||
ReadOnly = true,
|
||||
ScrollBars = ScrollBars.Vertical,
|
||||
Size = new System.Drawing.Size(400, 300),
|
||||
WordWrap = true
|
||||
};
|
||||
|
||||
// Set up form
|
||||
this.ClientSize = new System.Drawing.Size(424, 361);
|
||||
this.Controls.Add(lblArraySize);
|
||||
this.Controls.Add(txtArraySize);
|
||||
this.Controls.Add(btnRun);
|
||||
this.Controls.Add(txtOutput);
|
||||
this.Name = "ArraySortGUI";
|
||||
this.Text = "Array Sort Demo";
|
||||
this.FormClosing += new FormClosingEventHandler((object sender, FormClosingEventArgs e) => {onCloseForm.Show(); });
|
||||
}
|
||||
|
||||
private void btnRun_Click(object sender, EventArgs e)
|
||||
{
|
||||
int size;
|
||||
if (!int.TryParse(txtArraySize.Text, out size) || size < 1)
|
||||
{
|
||||
MessageBox.Show("Размер массива должен быть числом больше 0!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
txtOutput.Clear();
|
||||
Utils.Arrays array1 = new Utils.Arrays(size, 100);
|
||||
Utils.Arrays array2 = new Utils.Arrays(array1);
|
||||
|
||||
txtOutput.AppendText("Для Массива 1 будет использована \"гномья сортировка\"" + Environment.NewLine);
|
||||
txtOutput.AppendText("Для Массива 2 будет использована \"сортировка шелла\"" + Environment.NewLine);
|
||||
|
||||
if (size <= 10)
|
||||
{
|
||||
txtOutput.AppendText("Массив 1 (с начальными значениями): " + Environment.NewLine + array1.ToString() + Environment.NewLine);
|
||||
txtOutput.AppendText("Массив 2 (с начальными значениями): " + Environment.NewLine + array2.ToString() + Environment.NewLine);
|
||||
}
|
||||
else
|
||||
{
|
||||
txtOutput.AppendText("Массивы не могут быть выведены на экран так как их размер больше 10" + Environment.NewLine);
|
||||
}
|
||||
|
||||
txtOutput.AppendText("Сортируем..." + Environment.NewLine);
|
||||
|
||||
time1 = array1.gnomeSort();
|
||||
time2 = array2.shellSort();
|
||||
|
||||
txtOutput.AppendText("Готово!" + Environment.NewLine);
|
||||
|
||||
if (size <= 10)
|
||||
{
|
||||
txtOutput.AppendText("Массив 1 (после гномьей сортировки): " + Environment.NewLine + array1.ToString() + Environment.NewLine);
|
||||
txtOutput.AppendText("Массив 2 (после сортировки шелла): " + Environment.NewLine + array2.ToString() + Environment.NewLine);
|
||||
}
|
||||
|
||||
txtOutput.AppendText($"Для сортировки 1 потребовалось {time1}мс" + Environment.NewLine);
|
||||
txtOutput.AppendText($"Для сортировки 2 потребовалось {time2}мс" + Environment.NewLine);
|
||||
}
|
||||
}
|
||||
}
|
120
GUI/ArraySortGUI.resx
Normal file
120
GUI/ArraySortGUI.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?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>
|
Loading…
x
Reference in New Issue
Block a user