zoukankan      html  css  js  c++  java
  • 插入排序

    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 }
  • 相关阅读:
    Git-远程版本库
    Git-Git分支
    Git-Git里程碑
    Git-冲突解决
    Git-Git库管理
    Git-Git克隆
    Git-改变历史
    Git-历史穿梭
    RHCE考试
    RHCSA考试
  • 原文地址:https://www.cnblogs.com/icxk/p/13672235.html
Copyright © 2011-2022 走看看