insertionsort.h

来自「datastucutre and algorithms, application」· C头文件 代码 · 共 24 行

H
24
字号
// insertion sort

#ifndef insertionSort_
#define insertionSort_

// optimize code for speed
#pragma optimize("t", on)

template<class T>
void insertionSort(T a[], int n)
{// Sort a[0:n-1] using the insertion sort method.
   for (int i = 1; i < n; i++)
   {// insert a[i] into a[0:i-1]
      T t = a[i];
      int j;
      for (j = i-1; j >= 0 && t < a[j]; j--)
         a[j+1] = a[j];
      a[j+1] = t;
   }
}

#pragma optimize("t", off)
#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?