(C#)插入排序 Insertion Sort

来源:互联网 发布:电脑用手机网络 编辑:程序博客网 时间:2024/05/16 01:03
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Sort{    class Insert    {        public static void InsertSort(List<int> list)        {            int tmp, j;            for (int i = 1; i < list.Count; ++i)            {                if (list[i] < list[i - 1])                {                    tmp = list[i];                    for (j = i - 1; j >= 0 && tmp < list[j]; --j)                    {                        list[j + 1] = list[j];                    }                    //for (j = i - 1; j >= 0;)                    //{                    //    if (tmp < list[j])                    //    {                    //        list[j + 1] = list[j];                    //        --j;                    //    }                    //    else                    //    {                    //        break;                    //    }                    //}                    list[j + 1] = tmp;                }            }        }    }}


 

原创粉丝点击