From e5c25add128177405183e1d193c1a6da51a0e61a Mon Sep 17 00:00:00 2001 From: Rajdeep Karmakar Date: Mon, 6 Apr 2020 19:13:52 +0530 Subject: [PATCH 1/2] Added read.me --- README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..82f561d --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +A p5 javascript project to visualise different Algorithms in action during execution. +Can be seen at +https://rajduino.github.io/Visualiser/index.html From c4bdedd48c941f1b2349805119d5ec29aab05489 Mon Sep 17 00:00:00 2001 From: rajduino Date: Tue, 7 Apr 2020 18:48:52 +0530 Subject: [PATCH 2/2] Cleaning up --- index.html | 1 - quickHoare.js | 54 -------------------------------------------------- quickLomuto.js | 4 ++-- sketch.js | 18 ++++++++--------- 4 files changed, 10 insertions(+), 67 deletions(-) delete mode 100644 quickHoare.js diff --git a/index.html b/index.html index 3ba149b..3f1a198 100644 --- a/index.html +++ b/index.html @@ -14,7 +14,6 @@ - diff --git a/quickHoare.js b/quickHoare.js deleted file mode 100644 index f7ce1ec..0000000 --- a/quickHoare.js +++ /dev/null @@ -1,54 +0,0 @@ -function QuickSortHoare() { - this.name = 'Quick sort (Hoare)'; - this.count = 40; - this.representation = 1; - this.sorter = function* quickSortHoare(arr, colors, start = 0, end = arr.length - 1, self = this) { - if (start < end) { - // Partition list with pivot - let ref = {}; - yield* self['helpers']['partition'](arr, colors, start, end, ref); - let p = ref['']; - - // Sort parts recursively - yield* self['sorter'](arr, colors, start, p, self); - yield* self['sorter'](arr, colors, p + 1, end, self); - } else { - colors[start] = color(128, 255, 51); - } - - return colors; - }; - this.helpers = { - partition: function* (arr, colors, start, end, j) { - let pivot = arr[start]; - let i = start - 1; - j[''] = end + 1; - - while (true) { - do { - ++i; - compares++; - } while (arr[i] < pivot); - - - do { - --j['']; - compares++; - } while (arr[j['']] > pivot); - - colors[i] = color('red'); - colors[j['']] = color('red'); - yield colors; - colors[i] = color('white'); - colors[j['']] = color('white'); - - if (i >= j['']) - break; - - swap(arr, i, j['']); - swaps++; - myDelay(100); - } - } - } -} \ No newline at end of file diff --git a/quickLomuto.js b/quickLomuto.js index f22f8b5..395b14b 100644 --- a/quickLomuto.js +++ b/quickLomuto.js @@ -1,5 +1,5 @@ -function QuickSortLomuto() { - this.name = 'Quick sort (Lomuto)'; +function QuickSort() { + this.name = 'Quick sort'; this.count = 40; this.representation = 1; this.sorter = function* (arr, colors, start = 0, end = arr.length - 1, self = this) { diff --git a/sketch.js b/sketch.js index 78103e2..3251a69 100644 --- a/sketch.js +++ b/sketch.js @@ -13,8 +13,7 @@ const selectionSortMax = new SelectionSortMax(); const selectionSortMin = new SelectionSortMin(); const insertionSort = new InsertionSort(); const mergeSort = new MergeSort(); -const quickSortLomuto = new QuickSortLomuto(); -const quickSortHoare = new QuickSortHoare(); +const quickSort = new QuickSort(); const DOT = 0, LINE = 1; @@ -36,8 +35,7 @@ const algorithms = { selectionSortMin, insertionSort, mergeSort, - quickSortLomuto, - quickSortHoare, + quickSort, auxualary: { name: 'And a lot more coming soon!!', count: 0, @@ -181,9 +179,9 @@ function setup() { function init(algo, length) { paused = true; w = width / length; - passes=0; - swaps=0; - compares=0; + passes = 0; + swaps = 0; + compares = 0; representation = algo['representation']; // Generation of array @@ -232,9 +230,9 @@ function draw() { stroke(0); rect(i * w, height - array[i], w, array[i]); textAlign(LEFT, TOP); - textSize(map(array.length,1,100,40,12)); + textSize(map(array.length, 1, 100, 40, 12)); fill(0); - text(int(array[i]/10),(i+0.1)*w,height-array[i]+(height*.005)); + text(int(array[i] / 10), (i + 0.1) * w, height - array[i] + (height * .005)); } else if (representation === DOT) { ellipse(i * w, height - array[i], w, w) } @@ -244,7 +242,7 @@ function draw() { stroke(0); fill(255); textSize(40); - text("Passes="+passes+" Swaps="+swaps+" Compares="+compares,width*0.2,50); + text("Passes=" + passes + " Swaps=" + swaps + " Compares=" + compares, width * 0.2, 50); } }