为什么显示不出来8呢??
#include<stdio.h>
#define MAXNUM 100
#define TRUE 1
#define FALSE 0
typedef int KeyType;
typedef int DataType;
typedef struct {
KeyType key;
} RecordNode;
typedef struct {
int n;
RecordNode record[MAXNUM];
} SortObject;
void merge(RecordNode r[], RecordNode r1[], int low, int m, int high) {
int i = low, j = m + 1, k = low;
while ( i <= m && j <= high ) {
if (r[i].key <= r[j].key)
r1[k++] = r[i++];
else r1[k++] = r[j++];
}
while (i <= m) r1[k++] = r[i++];
while (j <= high) r1[k++] = r[j++];
}
void mergePass(RecordNode r[], RecordNode r1[], int n, int length) {
int i = 0, j;
while(i + 2*length - 1 < n) {
merge(r, r1, i, i+length-1, i + 2*length - 1);
i += 2*length;
}
if(i + length - 1 < n - 1)
merge(r, r1, i, i+length-1, n-1);
else
for(j = i; j < n; j++) r1[j] = r[j];
}
void mergeSort(SortObject * pvector) {
RecordNode record[MAXNUM];
int length = 1;
while (length < pvector->n) {
mergePass(pvector->record, record, pvector->n, length);
length *= 2;
mergePass(record, pvector->record, pvector->n, length);
length *= 2;
}
}
SortObject vector = {8, 49,38,65,97,76,13,27,49};
int main(){
int i;
mergeSort(&vector);
for(i = 0; i < 8; i++)
printf("%d ", vector.record[i]);
getchar();
return 0;
}