#include <stdlib.h>#include <stdio.h>#include <dos.h>const int MAXSIZE = 20000;const int N = 5;int Data[MAXSIZE];void Print(){ int i; for (i = 0; i < MAXSIZE; i++) printf ("%d ", Data[i]);}void Create(){ int i; randomize(); for (i = 0; i < MAXSIZE; i++) Data[i] = random(1000); printf("\n");}void Swap(int *a, int *b){ int temp; temp = *a; *a = *b; *b = temp;}void PushDown_MinHeap(int first, int last){ long i, j, x; i = first; j = i * 2; x = Data[i]; while (j <= last){ if (j < last && Data[j] < Data[j+1]) j++; if (x < Data[j]){ Data[i] = Data[j]; i = j; j = 2 * i; } else break; } Data[i] = x;}void MinHeapSort(int first, int last){ int i; for (i = last / 2; i >= first; i--) PushDown_MinHeap(i, last); for (i = last; i > first; i--){ Swap(&Data[first], &Data[i]); PushDown_MinHeap(first, i - 1); }}void Sort(){ int i, j; for (i = 0; i < MAXSIZE-1; i++) for (j = i; j < MAXSIZE; j++) if (Data[i] < Data[j]) Swap(&Data[i], &Data[j]);}void main(){ struct time t1, t2; float t; printf ("%s\n","---------------"); Create(); Print(); gettime(&t1);// MinHeapSort(0, MAXSIZE-1); Sort(); gettime(&t2); printf ("%s\n","---------------");// Print(); t = 60*(t2.ti_min-t1.ti_min)+(t2.ti_sec-t1.ti_sec)+1/100*(t2.ti_hund-t1.ti_hund); printf("running time is: %f\n",t);}

评论