In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to use quick sort". In the daily operation, I believe that many people have doubts about how to use quick sort. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to use quick sort"! Next, please follow the editor to study!
Quick sort
What is a quick sort? quick sort was proposed by Turing Prize winner C. A. R. Hoare (1934 Mel -) in 1960.
Quick sorting is an improvement on bubble sorting. Its basic idea is that the sorted data 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. Then the two parts of data are quickly sorted according to this method, and the whole sorting process can be carried out recursively, so that the whole data becomes an ordered sequence. The whole sorting process takes only three steps:
In the dataset, select an element as the "pivot".
All elements that are smaller than the base are moved to the left of the base, and all elements greater than the base are moved to the right of the base.
Repeat the first and second steps for the left and right subsets of the Base until there is only one element left in all the subsets.
Quoted from wikipedia quick sorting (English: Quicksort), also known as partition exchange sorting (partition-exchange sort), a sorting algorithm, first proposed by Tony Hall. On average, sorting n items requires n log n comparisons. In the worst case, you need to compare (N2) times, but this is not common. In fact, quick sorting is usually significantly faster than other n log n algorithms because its internal loop (inner loop) can be implemented efficiently on most architectures.
Steps
Find the base point (middle number) of the array and create two empty arrays left and right
Traverse the array and compare each number in the array with the datum point. If it is smaller than the datum point, put it in the left array. If it is larger than the datum point, put it in the right array.
Make recursive calls to the arrays left and right.
Method one
Function quickSort (arr) {if (arr.length)
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.