算法一:插入排序(增量模式)
NOTE THAT :在同等的输入规模情况下,插入排序依据初始输入的不同,其运行时间会有差异(分析:最佳情况、最坏情况、平均情况)。
#include "iostream"
using namespace std;
// date : 2017.12.18 By:dlphay
// INSERTION_SORT_DLY
int main()
{
int A[6] = {31, 41, 59, 26, 41, 58};
int i = 0;
int j = 0;
int value = 0;
for (i = 0; i < 6; i++)
{
cout << A[i] << "\t" << endl;
if (i == 5) cout << "\n" << endl;
}
for (j = 1; j < 6; j++)
{
value = A[j];
i = j - 1;
// sort
while ((value < A[i]) && (i >= 0))
{
A[i + 1] = A[i];
i--;
}
A[i+1] = value;
}
for (i = 0; i < 6; i++)
{
cout << A[i] << "\t" << endl;
//if(i ==