From 2922a9396532913d2040c857cecdadd2be8adfc2 Mon Sep 17 00:00:00 2001 From: Xevion Date: Fri, 8 Nov 2019 14:54:17 -0600 Subject: [PATCH] cocktail shaker sort sketch --- sorting/README.md | 4 +++- sorting/insertion_sort_line/insertion_sort_line.pyde | 8 ++++++++ sorting/insertion_sort_line/sketch.properties | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 sorting/insertion_sort_line/insertion_sort_line.pyde create mode 100644 sorting/insertion_sort_line/sketch.properties diff --git a/sorting/README.md b/sorting/README.md index ee2ee88..bf41dec 100644 --- a/sorting/README.md +++ b/sorting/README.md @@ -6,4 +6,6 @@ Sketches that visualize sorting algorithms as they progress. ## Sketches -- **cocktail_shaker_line** - Sorting of a line using the cocktail shaker algorithm (double bouble sort I believe). Needs reworking as the colors and movement of the line is not as expected (colors shift, movement doesn't properly correlate). \ No newline at end of file +- **cocktail_shaker_line** - Sorting of a line using the cocktail shaker algorithm (double bouble sort I believe). Needs reworking as the colors and movement of the line is not as expected (colors shift, movement doesn't properly correlate). + +- **insertion_sort_line** - Sorting of a line using the insertion sort algorithm. \ No newline at end of file diff --git a/sorting/insertion_sort_line/insertion_sort_line.pyde b/sorting/insertion_sort_line/insertion_sort_line.pyde new file mode 100644 index 0000000..d9d0da3 --- /dev/null +++ b/sorting/insertion_sort_line/insertion_sort_line.pyde @@ -0,0 +1,8 @@ +def setup(): + +def draw(): + if unsorted: + get = unsorted.pop(0) + for index, num in enumerate(sorted): + if sorted[index] < sorted[index + 1] and sorted[index + 1] >= get: + sorted.append( diff --git a/sorting/insertion_sort_line/sketch.properties b/sorting/insertion_sort_line/sketch.properties new file mode 100644 index 0000000..2456b0a --- /dev/null +++ b/sorting/insertion_sort_line/sketch.properties @@ -0,0 +1,2 @@ +mode=Python +mode.id=jycessing.mode.PythonMode