void MSort ( ElemType *p,ElemType *p1, int s, int t ) |
{ /*将p[s…t]归并排序为p1[s…t]*/ |
if ( s==t ) p1[s]=p[s] |
else |
{ |
m= ( s+t ) /2; /*平分*p 表*/ |
MSort ( p,p2,s,m ); /*递归地将p[s…m]归并为有序的p2[s…m]*/ |
MSort ( p,p2,m+1,t ); /*递归地将p[m+1…t]归并为有序的p2[m+1…t]*/ |
Merge ( p2,p1,s,m+1,t ); /*将p2[s…m]和p2[m+1…t]归并到p1[s…t]*/ |
} |
} |
void MergeSort ( S_TBL *p ) |
{ /*对顺序表*p 作归并排序*/ |
MSort ( p->elem,p->elem,1,p->length ); |
} |