C#
09.C# - 알고리즘 : 정렬(Sort)
Godffs
2009. 8. 7. 21:31
반응형
정렬(Sort)-순서대로 정렬시키는 알고리즘으로 오름차순과 내림차순이 있습니다.
종류로는 : 선택정렬, 버블정렬, 퀵정렬, 삽입, 기수등이 있습니다.
using System;
public class 선택정렬
{
public static void Main()
{
//[1] Input
int[] data = { 7, 5, 6 };
//[2] Process
int temp = 0;
for (int i = 0; i < data.Length - 1; i++)
{
for (int j = i + 1; j < data.Length; j++)
{
if (data[i] > data[j])
{
temp = data[i];
data[i] = data[j];
data[j] = temp;
}
}
}
//[3] Output
for (int i = 0; i < data.Length; i++)
{
Console.Write("{0} ", data[i]);
}
Console.WriteLine();
}
}
오름차순(Ascending)정렬 : 1,2,3 ABC순 내림차순(Desending)정렬 : 3,2,1 다나가 순 |
종류로는 : 선택정렬, 버블정렬, 퀵정렬, 삽입, 기수등이 있습니다.
public class 선택정렬
{
public static void Main()
{
//[1] Input
int[] data = { 7, 5, 6 };
//[2] Process
int temp = 0;
for (int i = 0; i < data.Length - 1; i++)
{
for (int j = i + 1; j < data.Length; j++)
{
if (data[i] > data[j])
{
temp = data[i];
data[i] = data[j];
data[j] = temp;
}
}
}
//[3] Output
for (int i = 0; i < data.Length; i++)
{
Console.Write("{0} ", data[i]);
}
Console.WriteLine();
}
}
반응형