1
0
This commit is contained in:
Debug_pro
2026-06-07 18:14:39 +03:00
commit b74b40209b
24 changed files with 2528 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
using System.IO;
namespace Lab9.Services;
public static class ArrayIoService
{
private static readonly char[] Separators = [' ', ',', ';', '\n', '\r', '\t'];
public static int[] ReadArrayFromFile(string filePath)
{
var content = File.ReadAllText(filePath);
return content
.Split(Separators, StringSplitOptions.RemoveEmptyEntries)
.Select(int.Parse)
.ToArray();
}
}

View File

@@ -0,0 +1,25 @@
using Lab9.Models;
using Lab9.Strategies;
namespace Lab9.Services;
public class SortingContext
{
public SortingContext()
{
}
public SortingContext(ISortStrategy strategy)
{
ContextStrategy = strategy;
}
public ISortStrategy? ContextStrategy { get; set; }
public SortResult Execute(int[] array, bool ascending, bool enableLogging)
{
ArgumentNullException.ThrowIfNull(ContextStrategy);
return ContextStrategy.Sort(array, ascending, enableLogging);
}
}

40
Services/StepLogger.cs Normal file
View File

@@ -0,0 +1,40 @@
using System.Text;
namespace Lab9.Services;
public class StepLogger
{
private readonly StringBuilder _builder = new();
public void Header(string text)
{
_builder.AppendLine(text);
}
public void BlankLine()
{
_builder.AppendLine();
}
public void Line(string text)
{
_builder.AppendLine(text);
}
public void ArrayState(int[] array, params int[] highlightedIndices)
{
var highlighted = highlightedIndices.Length == 0
? new HashSet<int>()
: highlightedIndices.ToHashSet();
var parts = new string[array.Length];
for (var i = 0; i < array.Length; i++)
{
parts[i] = highlighted.Contains(i) ? $"[{array[i]}]" : array[i].ToString();
}
_builder.AppendLine(string.Join(" ", parts));
}
public override string ToString() => _builder.ToString();
}