In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the sorting algorithms commonly used in JavaScript, which are very detailed and have certain reference value. Friends who are interested must finish reading them.
I. Bubble sorting
Bubble sorting is one of the most commonly used sorting algorithms in our programming algorithms. in the learning stage, it is also the algorithm that most needs contact and understanding, so we put it first to learn.
Introduction to the algorithm:
1. Compare two adjacent elements and swap positions if the former is larger than the latter.
two。 In the first round, the biggest elements were put at the back.
3. Since the last element of each sort is the largest, there is no need to compare the last element in step 1.
Improvement of bubbling algorithm:
Set a flag to true if a swap occurs on this trip. Otherwise, false. If there is no exchange on this trip, the sorting has been completed.
Second, quick sorting
Introduction to the algorithm:
Quick sort is an improvement on bubble sorting, in which the first sort divides the data into two parts, one smaller than all the data in the other. It is then called recursively, performing a quick sort on both sides.
Third, select and sort
Introduction to the algorithm:
Selective sorting is to select the most from an unknown data space and put it into a new space.
IV. Insert sort
Introduction to the algorithm:
1. Start with the first element that is sorted by default
two。 Take out the next element and scan from back to front in the sorted sequence of elements
3. If the sorted element is larger than the extracted element, move it backward one bit respectively
4. Until the sorted element is found that is less than or equal to the extracted element, put the extracted element next to it
5. Repeat step 2
These are all the contents of this article entitled "what are the sorting algorithms commonly used in JavaScript?" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.