Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to realize merge sorting in Java

Shulou Source: shulou.com Published: 2022-06-02 10:13:02 11月09日 Update

It is believed that many inexperienced people are at a loss about how to achieve merging and sorting in Java. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Public class MergeSort {static int number=0; public static void main (String [] args) {int [] a = {26,5,98,108,28,99,100,56,34,1}; printArray ("before sorting:", a); MergeSort (a); printArray ("after sorting:", a) } private static void printArray (String pre,int [] a) {System.out.print (pre+ "\ n"); for (int item0 / right) return; int mid = (left + right) / 2; / / there are two Sort in the two-way merge sort, and multiple Sort can be written in the multi-path merge sort (a, left, mid) Sort (a, mid + 1, right); merge (a, left, mid, right);} private static void merge (int [] a, int left, int mid, int right) {int [] tmp = new int [a.length]; int R1 = mid + 1; int tIndex = left; int cIndex=left; / / merge while (left) one by one

Tags: Sort content array method more problem surplus helpless for this two reasons right multiple for this skills copies articles experience results industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux NVidia macOS Apple Docker