[C#예제]C#으로 버블정열구현(C#
Bubble정렬),C#/WPF/닷넷WPF/ASP.NET/ADO닷넷/닷넷교육/닷넷강좌학원/닷넷공부/닷넷책/닷넷객체지향교육
버블정렬은 인접한 값을 계속 비교하면서 위치를 바꾸면서 최대, 최소값을 구하는 정렬방식 입니다.
닷넷에서 C#을 이용하여 구현하시오.
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int[] b = new int[] { 99,8,4,6,9 };
int temp = 0;
for (int i = 0; i < b.Length; i++)
{
for (int j = i + 1; j < b.Length; j++)
{
if (b[i] > b[j])
{
temp = b[i];
b[i] = b[j];
b[j] = temp;
}
}
}
for (int i = 0; i < b.Length; i++)
{
Console.Write(b[i] + ", ");
}
}
}
}
댓글 없음:
댓글 쓰기