@@ -24,7 +24,8 @@ private static List<T> InternalMergeSort<T>(List<T> collection, int startIndex,
2424 {
2525 return collection ;
2626 }
27- else if ( collection . Count == 2 )
27+
28+ if ( collection . Count == 2 )
2829 {
2930 if ( comparer . Compare ( collection [ endIndex ] , collection [ startIndex ] ) < 0 )
3031 {
@@ -33,18 +34,16 @@ private static List<T> InternalMergeSort<T>(List<T> collection, int startIndex,
3334
3435 return collection ;
3536 }
36- else
37- {
38- int midIndex = collection . Count / 2 ;
3937
40- var leftCollection = collection . GetRange ( startIndex , midIndex ) ;
41- var rightCollection = collection . GetRange ( midIndex , ( endIndex - midIndex ) + 1 ) ;
38+ int midIndex = collection . Count / 2 ;
4239
43- leftCollection = InternalMergeSort < T > ( leftCollection , 0 , leftCollection . Count - 1 , comparer ) ;
44- rightCollection = InternalMergeSort < T > ( rightCollection , 0 , rightCollection . Count - 1 , comparer ) ;
40+ var leftCollection = collection . GetRange ( startIndex , midIndex ) ;
41+ var rightCollection = collection . GetRange ( midIndex , ( endIndex - midIndex ) + 1 ) ;
4542
46- return InternalMerge < T > ( leftCollection , rightCollection , comparer ) ;
47- }
43+ leftCollection = InternalMergeSort < T > ( leftCollection , 0 , leftCollection . Count - 1 , comparer ) ;
44+ rightCollection = InternalMergeSort < T > ( rightCollection , 0 , rightCollection . Count - 1 , comparer ) ;
45+
46+ return InternalMerge < T > ( leftCollection , rightCollection , comparer ) ;
4847 }
4948
5049
0 commit comments