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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            int[] a = { 118, 101, 105, 127, 112 };

            InsertSort(a);



            Console.ReadLine();
        }



        static void InsertSort(int[] array)
        {
            int j, t;

            for (int i = 1; i < array.Length; i++)
            {
                t = array[i];
                j = i - 1;


                while (j >= 0 && t < array[j]) 
                {
                    array[j + 1] = array[j];
                    j--;
                }

                array[j + 1] = t;

                Console.WriteLine("" + i + "步排序结果");

                for (int h = 0; h < array.Length; h++)
                {
                    Console.Write(" " + array[h].ToString());
                }
                Console.WriteLine();
            }


        }

    
    }

    


}

C# 插入排序算法

相关文章:

  • 2021-06-28
  • 2021-07-01
  • 2022-01-03
  • 2021-04-12
  • 2021-07-16
  • 2021-06-14
  • 2021-11-05
猜你喜欢
  • 2021-07-02
  • 2021-10-05
  • 2022-12-23
  • 2022-03-10
  • 2022-12-23
  • 2021-08-25
相关资源
相似解决方案