Insertion Sort Using List - ???
Условие:
Read a list of integers on the first line of the console. After that, sort the array, using the Insertion Sort algorithm, but instead of doing it in-place, add the result one by one to a list.
Оказа се много трудно сортиране и добавяне в друг List<> едновременно.
Първото сравнение и запис в result се получават, но след това нищоооо... Не мога да спазя така зададеното условие.
List<int> input = Console.ReadLine()
                                .Split(' ')
                                .Select(int.Parse)
                                .ToList();
            List<int> result = new List<int>(input.Count);
            result.Add(input[0]);
            if (input[1] < input[0])
            {
                result.Add(input[0]);
                result.Insert(0, input[1]);
            }
            else
            {
                result.Add(input[1]);
            }
List<int> input = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
List<int> result = new List<int>(input.Count);
for (int i = 0; i < input.Count; i++)
{
bool inserted = false;
for (int j = 0; j < result.Count; j++)
{
if(input[i] < result[j])
{
result.Insert(j, input[i]);
inserted = true;
break;
}
}
if(!inserted)
{
result.Add(input[i]);
}
}
Console.WriteLine(string.Join(" ", result));