버블 정렬을 사용하지 않고 Datatables.Can을 사용하지 않고도 .NET에서 가장 작은 배열에서 가장 큰 배열로 정렬하고 싶습니다. 누구든지 작업 완료 방법을 도와 줄 수 있습니까?.NET에서 가장 큰 것부터 가장 작은 것까지
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();
}
}
}
세 번째 루프에서 누락 된 것으로 보입니다 –
이 숙제입니까? 정렬 알고리즘을 검색하려고 할 수 있습니다. 빠른 정렬은 매우 보편적 인 범용 알고리즘입니다. –
정렬이 필요한 두 개의 배열이 있습니까? – user7116