2020-09-15 11:36:16

玩过扑克牌的人一般都有过从小到大将牌排好的习惯,当你抽到一张牌小于你手上某个位置上的拍的时候,你都会将新拿到的牌插入到适合的位置。

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Runtime.InteropServices;
 5 using System.Text;
 6 using System.Threading.Tasks;
 7 
 8 namespace SelectSort
 9 {
10     class Program
11     {
12         private static void selectSort(int[] array)
13         {
14             for (int i = 1; i < array.Length; i++)
15             {
16                 int target = array[i];
17                 int j = i - 1;
18                 while (j >= 0 && target < array[j])
19                 {
20                     array[j + 1] = array[j];
21                     j--;
22                 }
23                 array[j + 1] = target;
24             }
25 
26         }
27         static void Main(string[] args)
28         {
29             int[] array = { 5, 4, 3, 8, 7, 9, 1, 44, 0 };
30             selectSort(array);
31             for (int i = 0; i < array.Length; i++)
32             {
33                 Console.WriteLine(array[i]);
34             }
35             Console.ReadKey();
36         }
37     }
38 }
内容来源于网络如有侵权请私信删除

文章来源: 博客园

原文链接: https://www.cnblogs.com/icxk/p/13672235.html

你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!