In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how python implements the visualization of sorting algorithms. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
The main contents are as follows: 1. To realize the visualization of the classification algorithm, it is only necessary to color mark the change of each data.
2. Draw it as the data of a columnar image, empty the picture of the previous frame, cycle until the last ordered picture is displayed, and our sorting algorithm is completed in a visual loop.
You need a two-dimensional list (frames), where the elements are the list of data for each frame.
You also need to convert each data to class, with its own value properties and value properties, as well as the set_color () method.
Example
Def sort (li): # the elements in such an assigned frames list are lists one by one, and the data in each frame is an initial list assigned by the element frames = [li] ds = copy.deepcopy (li) # Used to store data after each frame change # Bubble sort: for i in range (32): for j in range (32-I-1): ds_r = copy.deepcopy (ds) # assign the data in a ds ds_ r [j] .set _ color ('# DC143C') # set the color of the data to'# DC143C' Ds_ r [j + 1] .set _ color ('# 7FFFAA') frames.append (ds_r) # appends the changed data of color to frmaes if DSS [j] .value > ds [j + 1] .value: ds [j + 1] Ds [j] = ds [j], ds [j + 1] frames.append (ds) # append the last sorted data to return frames. Thank you for reading! This is the end of this article on "how to achieve the visualization of sorting algorithms in python". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
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.