今天开始学习著名的算法巨作《Introduction to Algorithms(Sencond Edition)》
花了不少时间才把书中的伪代码解释看明白。然后阅读了其中的一个简单的范例。
以下是这个简单范例(插入排序)的C#代码实现

 1 namespace Algorithms
 2 {
 3     public class Sort
 4     {
 5         public void InsertionSort(int[] a)
 6         {
 7             int key, i;
 8             for (int j = 1; j < a.Length; j++)
 9             {
10                 key = a[j];
11 
12                 i = j - 1;
13 
14                 while (i > -1 && a[i] > key) 
15                 {
16                     a[i + 1= a[i];
17                     i--;
18                 }
19 
20                 a[i + 1= key;
21             }
22         }
23     }
24 }


 

相关文章:

  • 2021-08-18
  • 2021-08-23
  • 2021-11-16
  • 2021-08-31
  • 2021-11-02
  • 2021-12-08
  • 2021-09-23
  • 2021-06-30
猜你喜欢
  • 2021-09-30
  • 2021-05-30
  • 2021-05-23
  • 2022-12-23
  • 2022-01-12
  • 2021-09-13
  • 2021-06-25
相关资源
相似解决方案