#include <iostream> #include <iomanip> using namespace std; typedef struct { int key; int data; }LineList; void InsertSort(LineList R[], int n) { int i, j; LineList tmp; for(i=1;i<n;i++) { tmp = R[i]; j = i - 1; while(j>=0 && tmp.key < R[j].key)//元素后移,以使空出一个位置插入tmp { R[j+1] = R[j]; j--; } R[j+1] = tmp;//在j+1处插入tmp } } int main() { LineList R[10]; int A[] = {75, 87, 68, 92, 88, 61, 77, 96, 80, 72}; int i, n = 10; for(i = 0; i < n; i++) R[i].key = A[i]; InsertSort(R,n); for(i=0;i<n;i++) cout << setw(3) << R[i].key; cout << endl; }