Download insertionSort.py from shukdevdatta123/Sorting-Visualization: direct link, hf CLI and curl.
- Browser
- Download file 445 Bytes
-
https://huggingface.co/spaces/shukdevdatta123/Sorting-Visualization/resolve/1a247f5828b248381d49d62f2957cdc19bb8e453/insertionSort.py
- Command line
-
hf download hf://spaces/shukdevdatta123/Sorting-Visualization@1a247f5828b248381d49d62f2957cdc19bb8e453/insertionSort.py
-
curl -L -o insertionSort.py https://huggingface.co/spaces/shukdevdatta123/Sorting-Visualization/resolve/1a247f5828b248381d49d62f2957cdc19bb8e453/insertionSort.py
445 Bytes
| import time | |
| from colors import * | |
| def insertion_sort(data, draw_data, time_tick): | |
| for i in range(len(data)): | |
| temp = data[i] | |
| j = i | |
| while j > 0 and temp < data[j-1]: | |
| data[j] = data[j-1] | |
| j -= 1 | |
| data[j] = temp | |
| draw_data(data, [LIGHT_GREEN if x == j or x == i else BLUE for x in range(len(data))]) | |
| time.sleep(time_tick) | |
| draw_data(data, [BLUE for x in range(len(data))]) |