跳到主要内容

函数

#include <iostream>
using namespace std;

void InsertionSort(int cards[], int n)
{
for (int i = 1; i < n; i++)
{
int target = cards[i], min = 500, pos = -1;
for (int j = 0; j < i; j++)
if (cards[j] > target && cards[j] < min)
{
min = cards[j];
pos = j;
}
if (pos != -1)
{s
for (int j = i; j > pos; j--)
cards[j] = cards[j - 1];
cards[pos] = target;
}
}
}

int main()
{
int cards[13] = {311, 112, 402, 405, 206, 207, 101, 113, 208, 303, 304, 309, 410};
InsertionSort(cards, 13);
for (int i = 0; i < 13; i++)
cout << cards[i] << endl;
return 0;
}