/ / .NET od najväčšieho po najmenšie - c #, .net

.NET z najväčších na najmenších - c #, .net

Chcem zoradiť pole od najmenšej po najväčšiu v sieti .NET (c #) bez použitia triedenia bubliniek a bez použitia dátových tabuliek. Môže mi niekto pomôcť dokončiť úlohu?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//int[,] myArray = new int[4, 2];


//int[,] array_sorted = { { 20, 9, }, { 75, 25 }, { 90, 78, } };
int[,] array_sorted = { { 20, 9, }, { 75, 25 }, { 50, 92 }, { 9, 7 }, { 19, 78 }, { 50, 78 }, { 50, 98 }, { 23, 32 }, { 12, 232 }, { 45, 65 } };



Console.WriteLine("Before Bubble Sorting....");
for (int i = 0; i < array_sorted.GetLength(0); i++)
{
for (int j = 0; j < array_sorted.GetLength(1); j++)
{
Console.Write("{0,3}", array_sorted[i, j]); // respresent how the element should be represented
}
Console.WriteLine();
}
Console.WriteLine("After Bubble Sorting...");

for (int i = 0; i < array_sorted.GetLength(0); i++) // Array Sorting
{
for (int j = array_sorted.GetLength(1) - 1; j > 0; j--)
{
for (int k = 0; k < j; k++)
{
if (array_sorted[i, k] > array_sorted[i, k + 1])
{
int temp = array_sorted[i, k];
array_sorted[i, k] = array_sorted[i, k + 1];
array_sorted[i, k + 1] = temp;
}
}
}

}

for (int i = 0; i < array_sorted.GetLength(0); i++)
{
for (int j = 0; j < array_sorted.GetLength(1); j++)
{
Console.Write("{0 ,3}", array_sorted[i, j]);
}
Console.WriteLine();
}






Console.ReadLine();
}
}
}

odpovede:

2 pre odpoveď č. 1

Použite String.Sort a implementujte IComparer. Nemusíte to komplikovať. Array.Sort (new YourComparer ()). Prečítajte si o triedení polí MSDN a IComparer.


2 pre odpoveď č. 2

-1 za zrejmé domáce úlohy.

Každopádne tu je ľahká odpoveď:

var zoradené = array.OrderByDesc (x => x) .ToArray ();

dokončená. Netestovaný, takže gramatická chyba môže byť in. Používa LINQ, ktorý je platný podľa jazyka C #, ktorý zadáte ako jazyk.