直接插入排序
#include "stdafx.h"
#include<iostream>
using namespace std;
#define MAXN 1000
void swap(int *b, int *c);
int main()
{
int n = 0, i, j, x, a[MAXN] = { 0 };
while (cin>>x)
{
a[n] = x;
n++;
}
for (i = 1; i < n; ++i)
{
for (j = i; j > 0; --j)
{
if (a[j] < a[j - 1]) swap(&a[j], &a[j - 1]);
}
}
for (i = 0; i < n; ++i)
cout << a[i] << " ";
return 0;
}
void swap(int *b,int *c)
{
int temp;
temp = *c;
*c = *b;
*b = temp;
}