using System.Collections.Generic;
using System.Diagnostics;
public static void Main()
List<int> listToTest = new() { 3, 1, 2 };
Console.WriteLine(SortAndMeasureTime(GetAlgorithm("BubbleSort"), listToTest));
Console.WriteLine(SortAndMeasureTime(GetAlgorithm("MergeSort"), listToTest));
public static Algorithm GetAlgorithm(string name)
throw new Exception("Incorrect algorithm");
public static SortedList SortAndMeasureTime(Algorithm algorithm, List<int> elements)
Stopwatch stopwatch = new();
List<int> list = new(elements);
SortedList sortedList = new();
sortedList.ExecutionTime = stopwatch.Elapsed.TotalSeconds;
public interface Algorithm
void Sort(List<int> list);
public class MergeSort : Algorithm
public void Sort(List<int> list)
public class BubbleSort : Algorithm
public void Sort(List<int> list)
public List<int> List { get; set; }
public double ExecutionTime { get; set; }
public override string ToString() {
return "Sorted: " + string.Join(",", List) + ", Time: " + ExecutionTime + "s";