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/01 Report--
This article will explain in detail what the fast sorting method is in java. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Quick sorting method:
As the name suggests, quick sorting is a quick sorting algorithm in practice, especially useful in C++ or in sorting for java basic types. Its average elapsed time is 0 (N log N). The reason why the algorithm is particularly fast is mainly due to very concise and highly optimized internal loops.
Quick sorting is an improvement of the bubbling method. The data to be sorted is divided into two independent parts through a sort, and all the data in one part is smaller than all the data in the other part, and then the two parts of data are sorted quickly according to this method. The whole sorting process can be recursive, so that the whole data becomes an ordered sequence.
Schematic diagram:
Here, the leftmost element is defined as left. The rightmost element is right.
The value of p element is the sum of index 0 corresponding to 2 and index 7 corresponding to 5 divided by 2 to get the element 7 corresponding to index 3.
Swap positions with numbers greater than 7 on the left and numbers less than 7 on the right all the time, and the p in the middle changes position all the time.
Until the queue is over.
Code implementation:
Import java.util.Arrays; public class kuaisu {public static void main (String [] args) {int arrays [] = new int [] {2, 9, 7, 3, 3, 6, 5}; sort (arrays,0,arrays.length-1); System.out.println (Arrays.toString (arrays));} public static void sort (int arrays [], int left,int right) {intl = left; / / given subscript int r=right / / given subscript int temp; / / define a variable as the intermediate value to exchange the element position int pivot=arrays [(left+right) / 2] on the left and right sides; / / the intermediate value while (lumbr) {break;} temp=arrays [l]; arrays [l] = arrays [r]; arrays [r] = temp / / after exchanging arrays [l] = pivot if (arrays [l] = = pivot) {r Mustang;} if (arrays [r] = = pivot) {lumped colors;} if (ringing colors) {/ / Let the left element move the right element to the left and stagger the right element to the right. A pair of left if (leftl) {sort (arrays,l,right);}
The output from the console is as follows:
This is the end of the article on "what is fast sorting in java". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.