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.uj5u.com/qita/46383.html
標籤:其他
上一篇:二分查找及其變種演算法
