|
@@ -1,6 +1,7 @@
|
|
using Microsoft.Win32;
|
|
using Microsoft.Win32;
|
|
using System;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
|
|
+using System.Diagnostics;
|
|
using System.IO;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text;
|
|
@@ -24,15 +25,16 @@ namespace SORTER
|
|
{
|
|
{
|
|
int[] array;
|
|
int[] array;
|
|
string path;
|
|
string path;
|
|
|
|
+ FileInfo file;
|
|
|
|
+ Stopwatch linearTime;
|
|
|
|
+ Stopwatch minMaxTime;
|
|
|
|
+ Stopwatch bubleTime;
|
|
|
|
+ Stopwatch shuttleTime;
|
|
|
|
+ Stopwatch insertionTime;
|
|
|
|
|
|
public MainWindow()
|
|
public MainWindow()
|
|
{
|
|
{
|
|
InitializeComponent();
|
|
InitializeComponent();
|
|
- //linearSelectionSort(false);
|
|
|
|
- //methodMinMax();
|
|
|
|
- //BubbleSort();
|
|
|
|
- //ShuttleSort();
|
|
|
|
- //InsertionSort();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -50,9 +52,18 @@ namespace SORTER
|
|
arrayCopy[i] = array[i];
|
|
arrayCopy[i] = array[i];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ string pathCopy = file.DirectoryName + @"\Линейная сортировка.txt";
|
|
|
|
+ if (!File.Exists(pathCopy))
|
|
|
|
+ {
|
|
|
|
+ File.Copy(path, pathCopy);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ linearTime = new Stopwatch();
|
|
|
|
+ linearTime.Start();
|
|
|
|
+
|
|
if (ordering == false)
|
|
if (ordering == false)
|
|
{
|
|
{
|
|
- using (StreamWriter sw = new StreamWriter(path, false))
|
|
|
|
|
|
+ using (StreamWriter sw = new StreamWriter(pathCopy, false))
|
|
{
|
|
{
|
|
while (arraySorted.Count < 100)
|
|
while (arraySorted.Count < 100)
|
|
{
|
|
{
|
|
@@ -66,14 +77,14 @@ namespace SORTER
|
|
}
|
|
}
|
|
arrayCopy[index] = 100;
|
|
arrayCopy[index] = 100;
|
|
arraySorted.Add(max);
|
|
arraySorted.Add(max);
|
|
- sw.Write(arraySorted[index] + " ");
|
|
|
|
|
|
+ sw.Write(max + " ");
|
|
max = int.MinValue;
|
|
max = int.MinValue;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- using (StreamWriter sw = new StreamWriter(path, false))
|
|
|
|
|
|
+ using (StreamWriter sw = new StreamWriter(pathCopy, false))
|
|
{
|
|
{
|
|
while (arraySorted.Count < 100)
|
|
while (arraySorted.Count < 100)
|
|
{
|
|
{
|
|
@@ -87,18 +98,23 @@ namespace SORTER
|
|
}
|
|
}
|
|
arrayCopy[index] = 100;
|
|
arrayCopy[index] = 100;
|
|
arraySorted.Add(min);
|
|
arraySorted.Add(min);
|
|
- sw.Write(arraySorted[min] + " ");
|
|
|
|
|
|
+ sw.Write(min + " ");
|
|
min = int.MaxValue;
|
|
min = int.MaxValue;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ linearTime.Stop();
|
|
|
|
+
|
|
arraySorted.Clear();
|
|
arraySorted.Clear();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
void methodMinMax(bool? ordering)
|
|
void methodMinMax(bool? ordering)
|
|
{
|
|
{
|
|
|
|
+ minMaxTime = new Stopwatch();
|
|
|
|
+ minMaxTime.Start();
|
|
|
|
+
|
|
if(ordering == false)
|
|
if(ordering == false)
|
|
{
|
|
{
|
|
for (int i = 0; i < array.Length - 1; ++i)
|
|
for (int i = 0; i < array.Length - 1; ++i)
|
|
@@ -140,8 +156,15 @@ namespace SORTER
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ minMaxTime.Stop();
|
|
|
|
|
|
- using (StreamWriter sw = new StreamWriter(path, false))
|
|
|
|
|
|
+ string pathCopy = file.DirectoryName + @"\МинМакс.txt";
|
|
|
|
+ if(!File.Exists(pathCopy))
|
|
|
|
+ {
|
|
|
|
+ File.Copy(path, pathCopy);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ using (StreamWriter sw = new StreamWriter(pathCopy, false))
|
|
{
|
|
{
|
|
for (int i = 0; i < array.Length; ++i)
|
|
for (int i = 0; i < array.Length; ++i)
|
|
{
|
|
{
|
|
@@ -155,6 +178,9 @@ namespace SORTER
|
|
{
|
|
{
|
|
int temp;
|
|
int temp;
|
|
|
|
|
|
|
|
+ bubleTime = new Stopwatch();
|
|
|
|
+ bubleTime.Start();
|
|
|
|
+
|
|
if (ordering == false)
|
|
if (ordering == false)
|
|
{
|
|
{
|
|
for (int i = 0; i < array.Length - 1; i++)
|
|
for (int i = 0; i < array.Length - 1; i++)
|
|
@@ -186,7 +212,15 @@ namespace SORTER
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- using (StreamWriter sw = new StreamWriter(path, false))
|
|
|
|
|
|
+ bubleTime.Stop();
|
|
|
|
+
|
|
|
|
+ string pathCopy = file.DirectoryName + @"\Пузырьковая сортировка.txt";
|
|
|
|
+ if (!File.Exists(pathCopy))
|
|
|
|
+ {
|
|
|
|
+ File.Copy(path, pathCopy);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ using (StreamWriter sw = new StreamWriter(pathCopy, false))
|
|
{
|
|
{
|
|
for (int i = 0; i < array.Length; ++i)
|
|
for (int i = 0; i < array.Length; ++i)
|
|
{
|
|
{
|
|
@@ -201,6 +235,9 @@ namespace SORTER
|
|
|
|
|
|
int temp;
|
|
int temp;
|
|
|
|
|
|
|
|
+ shuttleTime = new Stopwatch();
|
|
|
|
+ shuttleTime.Start();
|
|
|
|
+
|
|
if(ordering == false)
|
|
if(ordering == false)
|
|
{
|
|
{
|
|
for (int i = 1; i < array.Length; i++)
|
|
for (int i = 1; i < array.Length; i++)
|
|
@@ -252,8 +289,15 @@ namespace SORTER
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ shuttleTime.Stop();
|
|
|
|
+
|
|
|
|
+ string pathCopy = file.DirectoryName + @"\Челночная сортировка.txt";
|
|
|
|
+ if (!File.Exists(pathCopy))
|
|
|
|
+ {
|
|
|
|
+ File.Copy(path, pathCopy);
|
|
|
|
+ }
|
|
|
|
|
|
- using (StreamWriter sw = new StreamWriter(path, false))
|
|
|
|
|
|
+ using (StreamWriter sw = new StreamWriter(pathCopy, false))
|
|
{
|
|
{
|
|
for (int i = 0; i < array.Length; ++i)
|
|
for (int i = 0; i < array.Length; ++i)
|
|
{
|
|
{
|
|
@@ -268,6 +312,9 @@ namespace SORTER
|
|
|
|
|
|
int index, temp;
|
|
int index, temp;
|
|
|
|
|
|
|
|
+ insertionTime = new Stopwatch();
|
|
|
|
+ insertionTime.Start();
|
|
|
|
+
|
|
if (ordering == false)
|
|
if (ordering == false)
|
|
{
|
|
{
|
|
for (int i = 0; i < array.Length; ++i)
|
|
for (int i = 0; i < array.Length; ++i)
|
|
@@ -305,7 +352,15 @@ namespace SORTER
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- using (StreamWriter sw = new StreamWriter(path, false))
|
|
|
|
|
|
+ insertionTime.Stop();
|
|
|
|
+
|
|
|
|
+ string pathCopy = file.DirectoryName + @"\Сортировка вставки.txt";
|
|
|
|
+ if (!File.Exists(pathCopy))
|
|
|
|
+ {
|
|
|
|
+ File.Copy(path, pathCopy);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ using (StreamWriter sw = new StreamWriter(pathCopy, false))
|
|
{
|
|
{
|
|
for (int i = 0; i < array.Length; ++i)
|
|
for (int i = 0; i < array.Length; ++i)
|
|
{
|
|
{
|
|
@@ -316,25 +371,32 @@ namespace SORTER
|
|
|
|
|
|
private void SortButton_Click(object sender, RoutedEventArgs e)
|
|
private void SortButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
{
|
|
- if (LinearButton.IsChecked == true)
|
|
|
|
- {
|
|
|
|
- linearSelectionSort(Ascending.IsChecked);
|
|
|
|
- }
|
|
|
|
- else if (minMaxButton.IsChecked == true)
|
|
|
|
- {
|
|
|
|
- methodMinMax(Ascending.IsChecked);
|
|
|
|
- }
|
|
|
|
- else if (BubbleButton.IsChecked == true)
|
|
|
|
|
|
+ if(string.IsNullOrEmpty(path))
|
|
{
|
|
{
|
|
- BubbleSort(Ascending.IsChecked);
|
|
|
|
|
|
+ MessageBox.Show("Для сортировки нужно выбрать файл");
|
|
}
|
|
}
|
|
- else if (ShuttleButton.IsChecked == true)
|
|
|
|
- {
|
|
|
|
- ShuttleSort(Ascending.IsChecked);
|
|
|
|
- }
|
|
|
|
- else if (InsertionButton.IsChecked == true)
|
|
|
|
|
|
+ else
|
|
{
|
|
{
|
|
- InsertionSort(Ascending.IsChecked);
|
|
|
|
|
|
+ if (LinearButton.IsChecked == true)
|
|
|
|
+ {
|
|
|
|
+ linearSelectionSort(Ascending.IsChecked);
|
|
|
|
+ }
|
|
|
|
+ else if (minMaxButton.IsChecked == true)
|
|
|
|
+ {
|
|
|
|
+ methodMinMax(Ascending.IsChecked);
|
|
|
|
+ }
|
|
|
|
+ else if (BubbleButton.IsChecked == true)
|
|
|
|
+ {
|
|
|
|
+ BubbleSort(Ascending.IsChecked);
|
|
|
|
+ }
|
|
|
|
+ else if (ShuttleButton.IsChecked == true)
|
|
|
|
+ {
|
|
|
|
+ ShuttleSort(Ascending.IsChecked);
|
|
|
|
+ }
|
|
|
|
+ else if (InsertionButton.IsChecked == true)
|
|
|
|
+ {
|
|
|
|
+ InsertionSort(Ascending.IsChecked);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -345,10 +407,11 @@ namespace SORTER
|
|
if (OPF.ShowDialog() == true)
|
|
if (OPF.ShowDialog() == true)
|
|
{
|
|
{
|
|
path = OPF.FileName;
|
|
path = OPF.FileName;
|
|
|
|
+ file = new FileInfo(path);
|
|
|
|
|
|
using (StreamReader sr = new StreamReader(OPF.FileName))
|
|
using (StreamReader sr = new StreamReader(OPF.FileName))
|
|
{
|
|
{
|
|
- string str = sr.ReadToEnd();
|
|
|
|
|
|
+ string str = sr.ReadToEnd().Trim();
|
|
string[] arrayStr = str.Split(" ");
|
|
string[] arrayStr = str.Split(" ");
|
|
|
|
|
|
array = new int[arrayStr.Length];
|
|
array = new int[arrayStr.Length];
|
|
@@ -360,5 +423,18 @@ namespace SORTER
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private void Diagram_Click(object sender, RoutedEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ if (linearTime == null || minMaxTime == null || bubleTime == null || shuttleTime == null || insertionTime == null)
|
|
|
|
+ {
|
|
|
|
+ MessageBox.Show("Для того, чтобы построить диаграмму, нужно отсортировать массив всемя способами");
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ Diagram wnd = new Diagram(linearTime.ElapsedTicks, minMaxTime.ElapsedTicks, bubleTime.ElapsedTicks, shuttleTime.ElapsedTicks, insertionTime.ElapsedTicks);
|
|
|
|
+ wnd.Show();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|