源程序:
#include <iostream>
#define N 5
using namespace std;
void insert_sort(int a[], int n) //直接插入排序
{
int i, j, temp;
for (i = 1; i < n; i++)
{
temp = a[i];
j = i - 1;
while (j >= 0 && temp < a[j])
{
a[j + 1] = a[j];
j--;
}
a[j + 1] = temp;
}
}
int main()
{
int *pArray;
int i;
pArray = new int[N]; //动态分配数组
//向数组中输入5个整数
for (i = 0; i < N; i++)
cin >> pArray[i];
cout << pArray[i]<<" ";
system("pause");
return 0;
}
运行结果:
原文地址:https://www.cnblogs.com/duanqibo/p/11971437.html
时间: 2024-10-16 04:07:04