//
//作者:陈继民
//把一些自己实现的算法记录一下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lib
{
public class Sort
{
/// <summary>
/// 插入递增排序
/// </summary>
/// <param name="unsortarray">排序前数组</param>
/// <returns>排序后数组</returns>
public int[] Insert(int[] unsortarray)
{
int[] insertResult = new int[unsortarray.Length];
insertResult[0] = unsortarray[0];
for (int i = 1; i < insertResult.Length; i++)
{
int key = unsortarray[i];
int j = i - 1;
while (j >= 0 && insertResult[j] > unsortarray[i])
{
insertResult[j + 1] = insertResult[j];
j = j - 1;
}
insertResult[j + 1] = key;
}
return insertResult;
}
/// <summary>
【排序算法】C#实现排序算法
最新推荐文章于 2025-05-10 13:43:38 发布