ProgLab1/Subprograms/ArraySortDemo.cs
2024-11-29 15:35:19 +04:00

71 lines
2.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using laba3.Core;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace laba3.Subprograms
{
/// <summary>
/// Compare computing time of 2 sorting methods;
/// Gnome sort and Shell sort;
/// </summary>
internal class ArraySortDemo
{
private long time1;
private long time2;
/// <summary>
/// Get values from keyboard, init arrays, start computing, print time;
/// Console will be clean!;
/// </summary>
public void Run()
{
Utils.Arrays array1;
Utils.Arrays array2;
int size;
size = ReadArrayLen();
array1 = new Utils.Arrays(size, 100);
array2 = new Utils.Arrays(array1);
Console.WriteLine("Для Массива 1 будет использована \"гномья сортировка\"");
Console.WriteLine("Для Массива 2 будет использована \"сортировка шелла\"");
if (size <= 10)
array1.print("с начальными значениями");
else
Console.WriteLine("Массивы не могут быть выведены на экран так как их размер больше 10");
Console.WriteLine("Сортируем...");
time1 = array1.gnomeSort();
time2 = array2.shellSort();
Console.WriteLine("Готово!");
if (size <= 10)
{
array1.print("после гномьей сортировки");
array2.print("после сортировки шелла ");
}
Console.WriteLine($"Для сортировки 1 потребовалось {time1}мс");
Console.WriteLine($"Для сортировки 2 потребовалось {time2}мс");
}
private int ReadArrayLen()
{
int size;
do
{
size = Utils.ReadInt("Размер массива для сортировки");
Console.Clear();
if (size < 1)
Console.WriteLine("Размер не может быть меньше 1!");
} while (size < 1);
return size;
}
}
}