버블 정렬 알고리즘

강kang·2024년 12월 11일

namespace 버블정렬
{
internal class Program
{
static void Main(string[] args)
{
int[] arr = new int[6] { 12, 23, 9, 88, 33, 12 };
int temp = 0;

        for (int i = 0; i < arr.Length - 1; i++)
        {
            for (int j = 0; j < arr.Length - 1 - i; j++)
            {
                if (arr[j] > arr[j + 1])
                {
                    temp = arr[j + 1];
                    arr[j + 1] = arr[j];
                    arr[j] = temp;
                }
            }
        }

        for (int i = 0; i < arr.Length; i++)
        {
            Console.Write($"{arr[i]} ");
        }
    }
}

}

profile
코딩

0개의 댓글