In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to insert java sorting algorithm, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!
1. Introduction to the simple principle of the algorithm
Insertion sorting (Insertion-Sort) is the simplest and most intuitive sorting algorithm. It works by building an ordered sequence, scanning the unsorted data from back to front in the sorted sequence, finding the corresponding position and inserting it. In other words, it is sorted based on comparison. Therefore, for this type of sorting, there are two basic operations:
① comparison operation
② exchange operation.
two。 Implementation steps for inserting sort
Start with the 0th element, which can be considered to have been sorted
Starting with the next element, scanning from back to front from the sorted element
If the sorted element is larger than the new element, the new element is moved forward
Repeat the steps of 3 until the sorted element is less than or equal to the new element
Insert a new element after the element
Repeat the above steps (2-5)
In short, move small data elements forward from behind.
3. Program implementation of insertion sorting
Examples are as follows:
The process of sorting according to 5pr 3pm 2pm 3 is as follows:
-
First trip: 3 5 2 3
The 0th element 5 is considered to be sorted, starting from the first element, the first element is smaller than the 0th element, so move forward.
-
Second trip: 2 3 5 3
The second element 2 is smaller than the first element 5, so the second element is moved forward, and then compared with the 0th element, it is still small, so move forward again.
-
The third trip: 2 3 3 5
The third element, compared with the second element, is smaller, so the third element is moved forward, and then compared with the previous element, it is not less than, so do not move, complete the sorting.
-
I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more 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.
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.