Bootstrap

C#冒泡插入选择排序代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp5
{
   
    internal class Program
    {

        public static void Buble(int key,int[] arr)
        {
            for (int i = 0; i < arr.Length - 1; i++)
            {
                for (int j = 1; j < arr.Length - i; j++)
                {
                    if (arr[j - 1] > arr[j])
                    {
                        key = arr[j - 1];
                        arr[j - 1] = arr[j];
                        arr[j] = key;
                    }
                }
            }
        }
        public static void Insert(int key, int[] arr)
        {
            int j, i;
            for( i =1;i < arr.Length; i++)
            {
                key = arr[i];
                for (j = i-1;j >=0 &&arr[j]>key; --j)
                {
                    arr[j+1] = arr[j];
                }
                arr[j + 1] = key;
            }
        }
        public static void SelectionSort( int[] arr)
        {
            int i, j, min;
            for(i =0; i < arr.Length; i++)
            {
                 min = i;
                for(j= i+1; j < arr.Length; j++)
                {
                    if (arr[j] < arr[min])
                    {
                        min = j;
                    }
                }
                int temp = arr[i];
                arr[i] = arr[min];
                arr[min] = temp;
            }
        }
        static void Main(string[] args)
        {
            int key=0;
            int[] arr = new int[] { 12, 32, 13, 22, 31, 41, 23 };
            SelectionSort(arr);
            foreach (int i in arr)
            {
                Console.WriteLine(i);
            }
        }
    }
}

;