In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "Java merge sort example Analysis". In the daily operation, I believe that many people have doubts about the Java merge sort example analysis problem. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "Java merge sort example Analysis". Next, please follow the editor to study!
Merging and sorting principle
1. As much as possible, a set of data is split into two subgroups with equal elements, and each subgroup continues to be split until the number of elements in each subgroup after the split is 1.
⒉ merges two adjacent subgroups into an ordered large group.
3. Repeat step 2 until there is only one group.
Merge sort API design class name Merge constructor Merge (): create Merge object member method
1.public static void sort (Comparable [] a): sorts the elements in an array
2.private static void sort (Comparable [] a hi int lo,int hi): sorts the elements in array a from index lo to index int
3.private static void merge (Comparable [] a mid lo,int mid,int hi): merge the data of these two subgroups in array an into an ordered large group (from index lo to index hi) from index mid+1 to index hi as one subgroup, and from index mid+1 to index int int as another subgroup.
4.private static boolean less (Comparable v comparison w): judge whether v is less than w
5.private static void exchange (Comparable [] a drawing int iline int j): swap the values at index I and index j in the an array
Member variable private static ComParable [] assit: the auxiliary array merge sorting code needed to complete the merge operation to sort the elements in the public class Merge {/ / auxiliary array private static Comparable [] assist; / / a pair of array a public static void sort (Comparable [] a) {assist=new Comparable [a.length]; int lo=0; int hi=a.length-1; sort (aJing lolohi) } / / sorting elements from lo to hi in a pair of array a private static void sort (Comparable [] a drawing int lo,int hi) {if (hi)
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.