Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize merge sorting in Java

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report