Сортировка подсчетом по убыванию - C#
Формулировка задачи:
Помогите пожалуйста программу на c# написать..
....................................
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _2
{
class Program
{
static void Main(string[] args)
{
int N;
Console.Write("Введите количество элементов массива: ");
N = int.Parse(Console.ReadLine());
int[] A = new int[N];
int[] new_A = new int[N];
int i;
int j;
for(i=0;i<N;i++)
{
Console.Write("Введите" + i + "элемент: ");
A[i] = int.Parse(Console.ReadLine());
}
for (i=0;i<N-1;i++)
{
k=1;
for(j=0;j<N-1;j++)
{if (A[i] < A[j]) k++;
A[i] = new_A[k];
}Решение задачи: «Сортировка подсчетом по убыванию»
textual
Листинг программы
using System;
using System.Linq;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
int[] arr1 = { 0, 1, 2, 3, 2, 1, 2, 3, 4, 3, 4, 3, 2, 3, 4, 0, 1, 4, 3 };
int[] arr2 = SortArray(arr1);
Console.WriteLine(string.Join(" ", arr2));
Console.ReadKey();
}
static int[] SortArray(int[] inputArray)
{
int[] countArray = new int[inputArray.Max() + 1];
for (int i = 0; i < inputArray.Length; i++)
{
countArray[inputArray[i]]++;
}
int[] sortedArray = new int[inputArray.Length];
int sortedArrayIndex = 0;
for (int i = countArray.Length-1; i >=0; i--)
{
for (int j = 0; j < countArray[i]; j++)
{
sortedArray[sortedArrayIndex++] = i;
}
}
return sortedArray;
}
}
}