In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the example analysis of the running process of python insertion sorting, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.
In order to ensure that the data is still orderly after insertion, it is necessary to determine the location of the inserted data.
1. Divide the data to be sorted into two intervals.
Ordered interval and disordered interval. The initial ordered interval contains only one element, the first element of the array, and the other is the unordered interval.
2. Select an element from the unordered interval in turn, and find a suitable insertion position in the ordered interval to ensure that the data in the sorted interval is always orderly.
3. Repeat this process.
Until the element of the unordered interval is empty, the algorithm ends.
Example
# encoding=utf-8def insert_sort (data_list):''No optimized version''count=0 # counts the number of cycles length = len (data_list) for i in range (1): # the element in the first position is the sorted interval by default So the subscript starts at 1 tmp = data_ list [I] # data to be inserted j = i while j > 0: # find the insertion position count + = 1 if tmp < data_ list [j-1]: data_ list [j] = data_ list [j-1] # element moves backward Vacate the insertion position else: break j-= 1 data_ list [j] = tmp # insert operation print (data_list) print (f "total number of loops is {count}") return data_list thank you for reading this article carefully. I hope the article "sample Analysis of the running process of python insertion sorting" shared by the editor will be helpful to you. At the same time, I also hope that you will support and pay attention to the industry information channel, and more related knowledge is waiting for you to learn!
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.