In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "how to achieve element increment in python quick sorting". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Concept
1. The fast sorting method, also known as the partition and exchange method, is an improvement of the bubbling sorting method.
Basic thought
2. Find a virtual intermediate value in the data, and then divide all the planned sorted data into two parts. In this data, data that is less than the intermediate value is placed on the left, and data greater than the intermediate value is placed on the right, and then the left and right data are processed in the same way until the sorting is complete.
Example
Def quick (data, start, end): # define fast sorting function if start > end: # if the start value is greater than the end value return # exit the program I, j = start, end result = data [start] # take the virtual intermediate value while True: # Loop while j > i and data [j] > = result: # find from right to left If the number found is less than the virtual median, stop the loop j = j-1 # look from right to left, position-1 while I < j and data [I] = j # exchange the virtual intermediate value and the number at the j position At this time, the virtual intermediate value becomes the real intermediate value data [start], data [j] = data [j], data [start] break # completes the first sort, and the quick sort function is called by dividing the left and right sides of quick (data, start, I-1) # with the middle value, and then quickly sort the left half of the data quick (data, I + 1, end) # to call the quick sort function. Then quickly sort the right half of the data data = [6, 1, 2, 7, 9, 3, 4, 5, 10, 8] # define the list and initialize print ("original data is:") print (data) # output raw data print ("-") quick (data, 0 (len (data)-1)) # call Quick sort The data starts from position 0 to the data length-1 until print ("sorted data is:") print (data) # output sorted data print ("- -") "python quick sorting how to achieve element increment" is introduced here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.