Home > database >  O bosses help me
O bosses help me

Time:01-11

Don't know what wrong, who help me
Generated by random function N random integer (200), for these are sorted from small to large,
Requirements: the heap sort,
#include
#include
#include
# define MaxSize 100

Typedef struct
{
Int the key;
} HeapType;

Void HeapAdjust (HeapType h [], int n, int m)
{
Int I=m;
H [0]=h [I];
Int j=2 * I;
While (j<=n)
{
If (j{
j=j+1;
}
If (h [j] key> H [0]. Key)
{
H=h [I] [j];
I=j;
J=2 * I;
}
The else
{
break;
}
}
H=h [0] [I];
}

Void HeapSort (HeapType h [], int n)
{
In the early//heap
int i;
For (I=n/2; i> 0; I -)
{
HeapAdjust (h, I, n);
}
//adjustment
for (i=n; i> 1; I -)
{
H [0]=h [1];
H [1]=h [I];
H=h [0] [I];
HeapAdjust (h, 1, I - 1);
}
}
Void ShowResult (int HeapType * h, n)//output
{
int i;
for(i=1; i<=n; I++)
{
Printf (" % d \ t ", h [I]);
If (I % 10==0)
{
printf("\n");
}
}
}

Void RandNum (HeapType * h, int n)
{
int i;
Srand ((unsigned) time (NULL));//initialize the random number
for(i=1; i<=n; I++)
{
H [I] key=rand () % 400 + 200;//random Numbers are produced more than 200
Printf (" % d \ t ", h [I]);
If (I % 10==0)//output 10 in a row number
{
printf("\n");
}
}
}
Int main ()
{
int n;
HeapType h (n + 1),
Printf (" produces a random integer number: \ n ");
The scanf (" % d ", & amp; N);
Printf (" produced by random to be sorted as: \ n ");
RandNum (h, n);
HeapSort (h, n);
Printf (" sorting result is: \ n ");
ShowResult (h, n);
return 0;
}
  • Related