Сортировка вставками - C# (185855)
Формулировка задачи:
Нужно отсортировать массив вставками, массив прописных букв, не могу понять, где ошибка
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Сортировка
{
class Program
{
static void InsertSort(ref Char[] A)
{
for (int i = 1; i < A.Length; i++)
{
int pos = 0;
char elem = A[i];
int v = elem.CompareTo(A[pos]);
while (v == 1) pos++;
for (int j = i - 1; j >= pos; j--)
A[j + 1] = A[j];
A[pos] = elem;
}
}
static void Main(string[] args)
{
Console.WriteLine("Введите количество прописных букв: ");
int n = Convert.ToInt32(Console.ReadLine());
char[] A = new char[n];
Random r = new Random();
for (int i = 0; i < A.Length; i++)
{
A[i] = Convert.ToChar(r.Next('A', 'Z' + 1));
Console.Write("{0} ", A[i]);
}
InsertSort(ref A);
for (int i = 0; i < A.Length; i++)
{
Console.Write("{0,5}", A[i]);
}
Console.ReadLine();
}
}
}Решение задачи: «Сортировка вставками»
textual
Листинг программы
while (v == 1) pos++;