c# 거품 정렬 알고리즘 예

1373 단어
 
  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace
{
    class Program
    {
        static void swap( ref int  atemp, ref int  btemp)// ref
        {
            int temp = atemp;
            atemp = btemp;
            btemp = temp;
        }
        static void Main(string[] args)
        {
            int temp=0;
            int[]arr={23,44,66,76,98,11,3,9,7};
            Console.WriteLine(" :");
            foreach(int item in arr)
            {
                Console.Write(item+" ");
            }
            Console.WriteLine();
            for(int i=0;i            {
                for(int j=0;j                {
                    if (arr[j] > arr[j + 1])
                          swap( ref  arr[j], ref arr[j + 1]);
                }
            }
           Console.WriteLine(" :");
           foreach(int item in arr)
           {
               Console.Write(item+" ");
            }
            Console.WriteLine();
            Console.ReadKey();

        }
    }
}

좋은 웹페이지 즐겨찾기