Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the merge sort in the C # sorting algorithm

Shulou Source: shulou.com Published: 2022-06-03 05:04:27 09月24日 Update

This article shows you what the merge sort is in the C# sorting algorithm, which is concise and easy to understand, which can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Code:

/ / merge sort (target array, start position of the child table, end position of the child table) private static void MergeSortFunction (int [] array, int first, int last) {try {if (first < last) / / the length of the child table is greater than 1, enter the following recursive processing {int mid = (first + last) / 2; / / the position of the subtable partition MergeSortFunction (array, first, mid) / / A pair of left subtables are divided recursively into MergeSortFunction (array, mid + 1, last); / / A pair of right subtables are divided recursively into MergeSortCore (array, first, mid, last) / / an ordered consolidation of left and right child tables (the core of merge sorting)}} catch (Exception ex) {}} / / the core of merge sorting: merge two ordered left and right child tables (distinguished by mid) into an ordered table private static void MergeSortCore (int [] array, int first, int mid, int last) {try {int indexA = first; / / the starting position of the left child table int indexB = mid + 1 / / the starting position of the right child table int [] temp = new int [last + 1]; / / declare the array (temporarily storing all ordered sequences of the left and right child tables): the length is equal to the sum of the lengths of the left and right child tables. Int tempIndex = 0; while (indexA

Tags: Sort order array position length recursion start algorithm Category side content right skill sequence Core goal knowledge part Loop conciseness Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft macOS NVidia Xiaomi Huawei