From 0fc0fdb125ac1b9776036397149ba97a2287c736 Mon Sep 17 00:00:00 2001 From: DIvan2000 Date: Sun, 22 Dec 2024 12:19:30 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=81=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BC=D0=B0=D1=81=D1=81=D0=B8=D0=B2=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core/Program.cs | 3 +- Core/Utils.cs | 9 +++ GUI/ArraySortGUI.Designer.cs | 39 ++++++++++++ GUI/ArraySortGUI.cs | 116 +++++++++++++++++++++++++++++++++ GUI/ArraySortGUI.resx | 120 +++++++++++++++++++++++++++++++++++ 5 files changed, 286 insertions(+), 1 deletion(-) create mode 100644 GUI/ArraySortGUI.Designer.cs create mode 100644 GUI/ArraySortGUI.cs create mode 100644 GUI/ArraySortGUI.resx diff --git a/Core/Program.cs b/Core/Program.cs index 7ada5da..dd827e6 100644 --- a/Core/Program.cs +++ b/Core/Program.cs @@ -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(); diff --git a/Core/Utils.cs b/Core/Utils.cs index 80720d4..7691c8f 100644 --- a/Core/Utils.cs +++ b/Core/Utils.cs @@ -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; + } + /// /// Sort this array with Gnome Sort; /// Avg time O(n^2); diff --git a/GUI/ArraySortGUI.Designer.cs b/GUI/ArraySortGUI.Designer.cs new file mode 100644 index 0000000..f270923 --- /dev/null +++ b/GUI/ArraySortGUI.Designer.cs @@ -0,0 +1,39 @@ +namespace ProgLab1.GUI +{ + partial class ArraySortGUI + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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 + } +} \ No newline at end of file diff --git a/GUI/ArraySortGUI.cs b/GUI/ArraySortGUI.cs new file mode 100644 index 0000000..4f6b753 --- /dev/null +++ b/GUI/ArraySortGUI.cs @@ -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); + } + } +} diff --git a/GUI/ArraySortGUI.resx b/GUI/ArraySortGUI.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/GUI/ArraySortGUI.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file