#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#define SIZE 30000
typedef int ELEMTYPE;
typedef struct
{
Elemtype key;
}SQ;
void Shellsort (elemtype a[],int n,int d[],int number)
{
int I,j,k,m,span;
SQ temp;
for (m=0;m<number;m++)/* Total number wheel sort */
{
SPAN=D[M];
for (k=0;k<span;k++)/* In each round of sorting, all elements are divided into a span group */
{
for (i=k; i+span<n;i+=span)
{
Temp.key=a[i+span];
J=i;
while (J>-1&&temp.key<a[j])
{
A[J+SPAN]=A[J];
J-=span;
}
A[j+span]=temp.key;
}
}
}
}
void Insertsort (Elemtype a[],int N)
{
int i,j;
SQ temp;
for (i=0;i<n-1;i++)
{
TEMP.KEY=A[I+1];
J=i;
while (J>-1&&temp.key<a[j])
{
A[J+1]=A[J];
j--;
}
A[j+1]=temp.key;
}
}
void Quicksort (Elemtype a[],int low,int High)/*low,high marks the starting and ending positions of the elements to be sorted, respectively */
{
int i,j;
SQ temp;
I=low,j=high;
Temp.key=a[low]; /* Use the first element as the standard element */
while (I<J)
{
while (I<j&&temp.key<=a[j])/* Array right-hand scan */
j--;
if (I<J)
{
A[I]=A[J];
i++;
}
while (I<j&&a[i]<temp.key)
i++;
if (I<J)
{
A[j]=a[i];
j--;
}
}
A[i]=temp.key;
if (low<i) Quicksort (a,low,i-1); /* Recursive left-hand collection */
if (I}
void product (Elemtype a[])
{int i;
for (i=0;i<30000;i++)
{A[i]=rand ();
printf ("%10d", A[i]);
if ((i+1)%6==0) printf ("\ n");
}
}
int main ()
{Elemtype a[size],b[5]={2500,500,100,20,1};
clock_t Start,end; /*typedef Long clock_t;*/
Start=clock ();/* Srand () sets the random seed, and the return value of the time () function is the parameter of the Srand function! */
Product (a);
Quicksort (a,0,size-1);
End=clock ();
printf ("\n%lf\n", (double) (End-start)/clocks_per_sec); /* constant CLOCKS_PER_SEC, which is used to indicate how many clock units are in a second */
Start=clock ();
Product (a);
Insertsort (a,10000);
End=clock (); printf ("\n%lf\n", (double) (End-start)/clocks_per_sec);
Start=clock ();
Product (a);
Shellsort (a,10000,b,5);
End=clock (); printf ("\n%lf\n", (double) (End-start)/clocks_per_sec);
return 0;
}
Several sorts of data structure C language