At noon today, I am free to help you sort and combineAlgorithm(Recursive C # Version)
Let's take a look at the basic strategy of the next merge and sort-balancing and simple binary division:
• The columns to be sorted are simply divided into left columns of roughly equal sizes.
• The right two segments, and then recursively add the two sub-Columns
• Merge and sort rows, and use these two sub-columns to obtain
• Ordering, merge them in an orderly manner in a work zone, and finally use
• Update the original element to be sorted by sorting all columns in the work area
• Columns are required for sorting element columns.
The format of the token is as follows:
Int [] Ar = { 1 , 4 , 34 , 8 , 78 , 4 , 5 , 6 , 9 , 34 , 65 , 78 , 9 , 12 } ;
This . Mergesoft ( Ref Ar, 0 , Ar. Length - 1 );
For ( Int I = 0 ; I < Ar. length; I ++ )
{
Ar [I];
}
The Zookeeper program is as follows:
Private Void Mergesoft ( Ref Int [] ARRA, Int Left, Int Right)
{
If (Left < Right)
{
Int Mid = (Left + Right) / 2 ;
Mergesoft ( Ref ARRA, left, mid );
Mergesoft ( Ref ARRA, mid + 1 , Right );
Int [] ARRC = Merge (ARRA, left, mid, right );
Copyarray ( Ref ARRA, ARRC, left, right );
}
}
Sort the Left and Right Parts
Private Int [] Merge ( Int [] ARRA, Int Left, Int Mid, Int Right)
{
Int [] Arrb = New Int [Right - Left + 1 ];
Int I = Left, J = Mid + 1 , K = 0 ;
While (I <= Mid) && J <= Right)
If (ARRA [I] <= ARRA [J]) arrb [K ++ ] = ARRA [I ++ ];
Else Arrb [K ++ ] = ARRA [J ++ ];
If (I > Mid && J <= Right)
For ( Int Q = J; q <= Right; q ++ )
Arrb [K ++ ] = ARRA [Q];
If (J > Right && I <= Mid)
For ( Int Q = I; q <= Mid; q ++ )
Arrb [K ++ ] = ARRA [Q];
Return Arrb;
}
Merge sorted data into the original data group
Private Void Copyarray ( Ref Int [] ARRA, Int [] ARRC, Int Left, Int Right)
{
For ( Int I = Left, J = 0 ; I <= Right && J < ARRC. length; I ++ , J ++ )
ARRA [I] = ARRC [J];
}