cxfans
9/8/2019 - 1:10 AM

插入排序 #Algorithm

插入排序 #Algorithm

typedef struct ElemType {
    char data[16];
    int key;
} ElemType;

void InsertSort(ElemType A[], int n) {
    int i, j;
    for (i = 2; i <= n; i++) {
        if (A[i].key < A[i - 1].key) {
            A[0] = A[i];
            for (j = i - 1; A[0].key < A[j].key; j--) {
                A[j + 1] = A[j];
            }
            A[j + 1] = A[0];
        }
    }
}