kopia lustrzana https://github.com/villares/sketch-a-day
selection sort
rodzic
88cc1e89f2
commit
90c21afe1d
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 410 KiB |
|
@ -0,0 +1,35 @@
|
|||
|
||||
nums = [random(512) for _ in range(512)]
|
||||
i = 0
|
||||
|
||||
def setup():
|
||||
size(512, 512)
|
||||
colorMode(HSB)
|
||||
|
||||
def draw():
|
||||
background(200)
|
||||
global i
|
||||
for x, n in enumerate(nums):
|
||||
stroke(n / 2, 255, 255)
|
||||
line(x, n, x, height)
|
||||
tam = len(nums)
|
||||
if i < width - 1:
|
||||
m = i
|
||||
for j in range(i + 1, tam):
|
||||
if nums[j] < nums[m]:
|
||||
m = j
|
||||
if nums[i] != nums[m]:
|
||||
nums[i], nums[m] = nums[m], nums[i]
|
||||
i += 1
|
||||
|
||||
|
||||
def selection_sort(nums):
|
||||
# int i, j, m, aux;
|
||||
tam = len(nums)
|
||||
for i in range(tam - 1):
|
||||
m = i
|
||||
for j in range(i + 1, tam):
|
||||
if nums[j] < nums[m]:
|
||||
m = j
|
||||
if nums[i] != nums[m]:
|
||||
nums[i], nums[m] = nums[m], nums[i]
|
|
@ -26,6 +26,12 @@ Some of the tools I have used:
|
|||
|
||||
---
|
||||
|
||||

|
||||
|
||||
[sketch_2020_10_06sel_sort](https://github.com/villares/sketch-a-day/tree/master/2020/sketch_2020_10_06sel_sort) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
|
||||
---
|
||||
|
||||

|
||||
|
||||
[sketch_2020_10_05d](https://github.com/villares/sketch-a-day/tree/master/2020/sketch_2020_10_05d) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||
|
|
Ładowanie…
Reference in New Issue