Repository navigation
Expand file tree
/
Copy pathquick_sort.html
More file actions
761 lines (703 loc) · 24.5 KB
/
Copy pathquick_sort.html
File metadata and controls
761 lines (703 loc) · 24.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
<title>Quick Sort</title>
<link rel="stylesheet" href="demo-theme.css" />
<style>
:root {
--page-max-width: 1560px;
--console-cols: 3fr 2fr;
}
/* ---- stage: the recursion tree — grows one level at a time as each
partition reveals its two new groups; unlike merge sort's fixed
index-range split, group sizes here depend entirely on the data ---- */
.stage {
position: relative;
background: var(--surface-sunken);
border-radius: 8px;
border: 1px solid var(--line);
padding: 1rem 0.9rem 0.8rem;
}
.tree {
overflow-x: auto;
overflow-y: auto;
max-height: 520px;
padding-bottom: 4px;
}
.tree-node {
display: flex;
flex-direction: column;
align-items: stretch;
min-width: 0;
}
.node-head {
font-family: var(--mono);
font-size: 0.62rem;
color: var(--ink-faint);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin-bottom: 3px;
transition: color 160ms ease;
}
.result-label {
font-family: var(--mono);
font-size: 0.56rem;
letter-spacing: 0.05em;
text-transform: uppercase;
color: var(--ink-faint);
margin: 6px 0 3px;
}
.cells {
display: flex;
gap: 2px;
}
.given-row {
border-top: 2px solid transparent;
padding-top: 4px;
}
.cell {
flex: 1 1 0;
min-width: 0;
}
.cell-box {
height: 32px;
min-width: 0;
border-radius: 5px;
border: 1px solid var(--line);
background: var(--surface);
display: flex;
align-items: center;
justify-content: center;
font-family: var(--mono);
font-weight: 700;
font-size: 0.72rem;
color: var(--ink);
font-variant-numeric: tabular-nums;
transition:
background-color 160ms ease,
border-color 160ms ease,
color 160ms ease,
box-shadow 160ms ease,
opacity 160ms ease;
}
.cell.is-pivot .cell-box {
border: 2px solid var(--accent);
font-weight: 800;
}
.cell.is-pending .cell-box {
border-style: dashed;
background: transparent;
color: var(--ink-faint);
}
.cell.is-read .cell-box {
border-color: var(--active);
box-shadow: 0 0 0 2px var(--active) inset;
color: var(--active);
}
.cell.is-done .cell-box {
background: var(--sorted);
border-color: var(--sorted);
color: var(--accent-ink);
}
.cell.is-consumed .cell-box {
opacity: 0.32;
text-decoration: line-through;
}
.cell.is-flash .cell-box {
animation: cellFlash 420ms ease-out;
}
@keyframes cellFlash {
0% {
filter: brightness(1);
}
35% {
filter: brightness(1.9);
}
100% {
filter: brightness(1);
}
}
.tree-node.is-active-node > .node-head {
color: var(--accent);
font-weight: 700;
}
.tree-node.is-active-node > .given-row {
border-top-color: var(--accent);
}
.children {
display: flex;
gap: 8px;
margin-top: 10px;
padding-top: 12px;
border-top: 1px solid var(--line);
position: relative;
}
.children > .tree-node {
position: relative;
}
.children > .tree-node::before {
content: "";
position: absolute;
top: -12px;
left: 50%;
width: 1px;
height: 12px;
background: var(--line);
}
/* this demo's legend dots represent bordered cell states, not filled bars */
.dot {
border: 1px solid var(--line);
}
.dot.accent {
background: var(--surface);
border-color: var(--accent);
}
.dot.active {
background: var(--active);
border-color: var(--active);
}
.dot.sorted {
background: var(--sorted);
border-color: var(--sorted);
}
</style>
<div class="page">
<header>
<div class="header-copy">
<div class="eyebrow">Algorithm Visualizer</div>
<h1>Quick Sort</h1>
<p class="lede">
Quick sort picks a pivot, partitions the rest into a "≤ pivot" group
and a "> pivot" group, then recursively sorts each before
recombining as sorted(≤) + pivot + sorted(>). Unlike merge sort's
even halves, group sizes depend entirely on the data — a lucky pivot
splits evenly, an unlucky one can chain into one long branch.
</p>
<div class="specs">
<span class="spec"
><span data-icon="badge-time"></span><b>Time</b> O(n log n) avg ·
O(n²) worst</span
>
<span class="spec"
><span data-icon="badge-space"></span><b>Space</b> O(n)</span
>
<span class="spec"><b>Stable</b> no</span>
<span class="spec"><b>In-place</b> no</span>
</div>
</div>
<button type="button" class="theme-toggle" id="themeToggle">
<span data-icon="sun"></span>
<span class="theme-toggle-label">Light</span>
</button>
</header>
<div class="console">
<section class="panel">
<div class="panel-head">
<span class="panel-title">Stage</span>
<span class="status" id="status">Ready — press Play or Step</span>
</div>
<div class="stage-wrap">
<div class="stage" id="stage">
<div class="tree" id="tree"></div>
</div>
<div class="legend">
<span><span class="dot accent"></span>pivot</span>
<span><span class="dot active"></span>comparing</span>
<span><span class="dot sorted"></span>sorted</span>
</div>
</div>
<div class="controls">
<div class="control-buttons">
<button id="btnPlay" class="primary">Play</button>
<button id="btnStep">Step</button>
<button id="btnReset">Reset</button>
<button id="btnShuffle">Shuffle</button>
</div>
<div class="control-sliders">
<div class="slider-group">
<div class="slider-label-row"><span>Size</span></div>
<input type="range" id="size" min="5" max="30" value="15" step="5" />
<div class="slider-value" id="sizeValue">15 items</div>
</div>
<div class="slider-group">
<div class="slider-label-row">
<span>Slow</span><span>Fast</span>
</div>
<input
type="range"
id="speed"
min="100"
max="800"
value="400"
step="100"
/>
<div class="slider-value" id="speedValue">400 ms / step</div>
</div>
</div>
</div>
<div class="stats">
<div class="stat">
<div class="stat-label">Comparisons</div>
<div class="stat-value" id="statCompare">0</div>
</div>
<div class="stat">
<div class="stat-label">Partitions</div>
<div class="stat-value" id="statPartitions">0</div>
</div>
<div class="stat">
<div class="stat-label">Pivot</div>
<div class="stat-value" id="statPivot">–</div>
</div>
</div>
</section>
<section class="panel">
<div class="lang-tabs" id="langTabs"></div>
<div class="panel-head">
<span class="panel-title" id="codeFilename"
>javascript/code/sort/quickSort.js</span
>
</div>
<div class="code" id="code"></div>
</section>
</div>
<div aria-hidden="true" style="height: 2rem"></div>
</div>
<script src="icons.js"></script>
<script src="demo-engine.js"></script>
<script>
(function () {
"use strict";
window.Icons.mount();
DemoEngine.initTheme("quick-sort");
var LANGS = {
js: {
label: "JS",
icon: "lang-js",
file: "javascript/code/sort/quickSort.js",
keywords: ["function", "const", "let", "if", "return", "for", "else"],
lines: [
{ text: "function quickSort(arr) {" },
{ text: " if (arr.length <= 1) {", group: "base" },
{ text: " return arr;", group: "base" },
{ text: " }", group: "base" },
{ text: " const pivot = arr[0];", group: "pivot" },
{ text: " const left = [];", group: "pivot" },
{ text: " const right = [];", group: "pivot" },
{ text: " for (let i = 1; i < arr.length; i++) {" },
{ text: " if (arr[i] < pivot) {", group: "assign-left" },
{ text: " left.push(arr[i]);", group: "assign-left" },
{ text: " } else {" },
{ text: " right.push(arr[i]);", group: "assign-right" },
{ text: " }" },
{ text: " }" },
{
text: " return [...quickSort(left), pivot, ...quickSort(right)];",
group: "combine",
},
{ text: "}" },
],
},
csharp: {
label: "C#",
icon: "lang-csharp",
file: "csharp/Code/Sort/QuickSort.cs",
keywords: ["public", "class", "static", "int", "if", "return"],
lines: [
{ text: "public class QuickSort" },
{ text: "{" },
{ text: " public static int[] Sort(int[] arr)" },
{ text: " {" },
{ text: " if(arr.Length <= 1){", group: "base" },
{ text: " return arr;", group: "base" },
{ text: " }", group: "base" },
{ text: " int pivot = arr[0];", group: "pivot" },
{
text: " int[] left = arr[1..].Where(x => x <= pivot).ToArray();",
group: "assign-left",
},
{
text: " int[] right = arr[1..].Where(x => x > pivot).ToArray();",
group: "assign-right",
},
{
text: " return [..Sort(left), pivot, ..Sort(right)];",
group: "combine",
},
{ text: " }" },
{ text: "}" },
],
},
java: {
label: "Java",
icon: "lang-java",
file: "java/src/main/java/sort/QuickSort.java",
keywords: ["public", "class", "static", "int", "if", "else", "for", "return", "new"],
lines: [
{ text: "public class QuickSort {" },
{ text: " public static int[] sort(int[] arr) {" },
{ text: " if (arr.length <= 1) {", group: "base" },
{ text: " return arr;", group: "base" },
{ text: " }", group: "base" },
{ text: " int pivotIndex = arr.length / 2;", group: "pivot" },
{ text: " int pivot = arr[pivotIndex];", group: "pivot" },
{ text: " int leftCount = 0;" },
{ text: " int rightCount = 0;" },
{ text: " for (int i = 0; i < arr.length; i++) {" },
{ text: " if (i != pivotIndex) {" },
{ text: " if (arr[i] <= pivot) leftCount++;", group: "assign-left" },
{ text: " else rightCount++;", group: "assign-right" },
{ text: " }" },
{ text: " }" },
{ text: " int[] left = new int[leftCount];" },
{ text: " int[] right = new int[rightCount];" },
{ text: " int l = 0, r = 0;" },
{ text: " for (int i = 0; i < arr.length; i++) {" },
{ text: " if (i != pivotIndex) {" },
{ text: " if (arr[i] <= pivot) left[l++] = arr[i];", group: "assign-left" },
{ text: " else right[r++] = arr[i];", group: "assign-right" },
{ text: " }" },
{ text: " }" },
{ text: " int[] leftSorted = sort(left);", group: "combine" },
{ text: " int[] rightSorted = sort(right);", group: "combine" },
{ text: " int[] result = new int[arr.length];", group: "combine" },
{
text: " System.arraycopy(leftSorted, 0, result, 0, leftSorted.length);",
group: "combine",
},
{ text: " result[leftSorted.length] = pivot;", group: "combine" },
{
text: " System.arraycopy(rightSorted, 0, result, leftSorted.length + 1, rightSorted.length);",
group: "combine",
},
{ text: " return result;", group: "combine" },
{ text: " }" },
{ text: "}" },
],
},
python: {
label: "Python",
icon: "lang-python",
file: "python/code/sort/quick_sort.py",
keywords: ["def", "if", "return", "for", "in"],
lines: [
{ text: "def sort(arr):" },
{ text: " if len(arr) <= 1:", group: "base" },
{ text: " return arr", group: "base" },
{ text: " pivot = arr[0]", group: "pivot" },
{ text: " left = [x for x in arr[1:] if x <= pivot]", group: "assign-left" },
{ text: " right = [x for x in arr[1:] if x > pivot]", group: "assign-right" },
{ text: " return sort(left) + [pivot] + sort(right)", group: "combine" },
],
},
go: {
label: "Go",
icon: "lang-go",
file: "go/code/sort/quick_sort.go",
keywords: ["func", "if", "return", "for", "else", "range", "var"],
lines: [
{ text: "func QuickSort(arr []int) []int {" },
{ text: " if len(arr) <= 1 {", group: "base" },
{ text: " return arr", group: "base" },
{ text: " }", group: "base" },
{ text: " pivot := arr[0]", group: "pivot" },
{ text: " var left, right []int", group: "pivot" },
{ text: " for _, v := range arr[1:] {" },
{ text: " if v <= pivot {", group: "assign-left" },
{ text: " left = append(left, v)", group: "assign-left" },
{ text: " } else {" },
{ text: " right = append(right, v)", group: "assign-right" },
{ text: " }" },
{ text: " }" },
{ text: " left = QuickSort(left)", group: "combine" },
{ text: " right = QuickSort(right)", group: "combine" },
{ text: " return append(append(left, pivot), right...)", group: "combine" },
{ text: "}" },
],
},
};
var codePanel = DemoEngine.mountCodePanel({
langs: LANGS,
order: ["js", "csharp", "java", "python", "go"],
defaultLang: "js",
codeEl: document.getElementById("code"),
filenameEl: document.getElementById("codeFilename"),
tabsEl: document.getElementById("langTabs"),
});
var treeEl = document.getElementById("tree");
var statusEl = document.getElementById("status");
var statCompare = document.getElementById("statCompare");
var statPartitions = document.getElementById("statPartitions");
var statPivot = document.getElementById("statPivot");
var nodesByPath = {};
var comparisons = 0;
var partitions = 0;
function randomValues(n) {
var vals = [];
for (var k = 0; k < n; k++) vals.push(8 + Math.floor(Math.random() * 90));
return vals;
}
function makeCell(container, value) {
var el = document.createElement("div");
el.className = "cell";
var box = document.createElement("div");
box.className = "cell-box";
box.textContent = String(value);
el.appendChild(box);
container.appendChild(el);
return { el: el, box: box };
}
// Creates one node of the recursion tree: its "given" row shows the
// exact value list this recursive call received. Quick sort's groups
// aren't fixed index ranges of a shared array (unlike merge sort) —
// partitioning filters by value, so each node's own list is only known
// once its parent finishes partitioning, and the tree grows as the
// recursion actually happens rather than being laid out in advance.
function createNode(path, headLabel, values) {
var nodeEl = document.createElement("div");
nodeEl.className = "tree-node";
var headEl = document.createElement("div");
headEl.className = "node-head";
headEl.textContent = headLabel;
nodeEl.appendChild(headEl);
var givenRowEl = document.createElement("div");
givenRowEl.className = "cells given-row";
var givenCells = values.map(function (v) {
return makeCell(givenRowEl, v);
});
nodeEl.appendChild(givenRowEl);
var node = {
el: nodeEl,
headEl: headEl,
givenRowEl: givenRowEl,
givenCells: givenCells,
sortedCells: givenCells,
childrenEl: null,
};
nodesByPath[path] = node;
return node;
}
// Adds one cell live to a node's given row as the parent's partition
// loop classifies an element into it, so the left/right groups visibly
// fill up element-by-element instead of appearing complete all at once.
function appendGivenCell(node, value) {
var cell = makeCell(node.givenRowEl, value);
node.givenCells.push(cell);
node.el.style.flexGrow = String(node.givenCells.length);
flashCell(cell);
return cell;
}
function addGhostCell(node) {
var ghost = makeCell(node.givenRowEl, "–");
ghost.el.classList.add("is-pending");
node.givenCells.push(ghost);
}
// Creates the two (initially empty) child groups as soon as the pivot
// is chosen, so the partition loop has somewhere to place each element
// as it goes — rather than the groups appearing already-formed once
// the loop is done.
function attachChild(parentPath, childPath, side) {
var parent = nodesByPath[parentPath];
if (!parent.childrenEl) {
parent.childrenEl = document.createElement("div");
parent.childrenEl.className = "children";
parent.el.appendChild(parent.childrenEl);
}
var label = (side === "left" ? "≤ " : "> ") + parent.pivotValue;
var child = createNode(childPath, label, []);
child.el.style.flexGrow = "1";
parent.childrenEl.appendChild(child.el);
return child;
}
function revealSorted(path, values) {
var node = nodesByPath[path];
var label = document.createElement("div");
label.className = "result-label";
label.textContent = "sorted";
node.el.appendChild(label);
var rowEl = document.createElement("div");
rowEl.className = "cells result-row";
var cells = values.map(function (v) {
var c = makeCell(rowEl, v);
c.el.classList.add("is-done");
return c;
});
node.el.appendChild(rowEl);
node.sortedCells = cells;
cells.forEach(flashCell);
}
function buildTree(values) {
treeEl.innerHTML = "";
nodesByPath = {};
var root = createNode("root", "Input", values);
treeEl.appendChild(root.el);
}
function clearActiveNode() {
var prev = treeEl.querySelector(".tree-node.is-active-node");
if (prev) prev.classList.remove("is-active-node");
}
function setActiveNode(path) {
clearActiveNode();
var node = nodesByPath[path];
if (node) node.el.classList.add("is-active-node");
}
function clearReadPointers() {
var reads = treeEl.querySelectorAll(".cell.is-read");
reads.forEach(function (c) {
c.classList.remove("is-read");
});
}
function flashCell(cell) {
cell.el.classList.remove("is-flash");
void cell.el.offsetWidth;
cell.el.classList.add("is-flash");
}
function setStatus(html) {
statusEl.innerHTML = html;
}
// Mirrors the real recursive algorithm exactly: pick arr[0] as pivot,
// partition the rest by comparing against it, then recurse into each
// side (true depth-first order — left fully resolved before right)
// before recombining as sorted(left) + pivot + sorted(right).
function* qsort(path, arr) {
if (arr.length <= 1) {
yield { type: "base", path: path, values: arr.slice() };
return arr.slice();
}
var pivot = arr[0];
yield { type: "pivot", path: path, pivot: pivot };
var left = [];
var right = [];
for (var i = 1; i < arr.length; i++) {
var goesLeft = arr[i] <= pivot;
yield {
type: "assign",
path: path,
idx: i,
val: arr[i],
pivot: pivot,
target: goesLeft ? "left" : "right",
};
if (goesLeft) left.push(arr[i]);
else right.push(arr[i]);
}
yield {
type: "partitioned",
path: path,
pivot: pivot,
left: left.slice(),
right: right.slice(),
};
var leftSorted = yield* qsort(path + "L", left);
var rightSorted = yield* qsort(path + "R", right);
var combined = leftSorted.concat([pivot], rightSorted);
yield { type: "combine", path: path, pivot: pivot, result: combined.slice() };
return combined;
}
function* quickSortSteps(arr) {
var sorted = yield* qsort("root", arr);
for (var i = 0; i < arr.length; i++) arr[i] = sorted[i];
yield { type: "done" };
}
function applyStep(step) {
if (step.type === "base") {
setActiveNode(step.path);
codePanel.highlightLine("base");
if (step.values.length > 0) {
nodesByPath[step.path].givenCells.forEach(function (c) {
c.el.classList.add("is-done");
});
}
setStatus(
step.values.length === 0
? "Empty group — already sorted (base case)"
: "Single element " + step.values[0] + " — already sorted (base case)",
);
return false;
} else if (step.type === "pivot") {
setActiveNode(step.path);
var pivotNode = nodesByPath[step.path];
pivotNode.pivotValue = step.pivot;
pivotNode.givenCells[0].el.classList.add("is-pivot");
attachChild(step.path, step.path + "L", "left");
attachChild(step.path, step.path + "R", "right");
codePanel.highlightLine("pivot");
partitions++;
statPartitions.textContent = partitions;
statPivot.textContent = step.pivot;
setStatus("Pivot = <span class=\"hl\">" + step.pivot + "</span>");
return false;
} else if (step.type === "assign") {
clearReadPointers();
var node = nodesByPath[step.path];
var cell = node.givenCells[step.idx];
cell.el.classList.add("is-read");
codePanel.highlightLine(step.target === "left" ? "assign-left" : "assign-right");
var childNode = nodesByPath[step.path + (step.target === "left" ? "L" : "R")];
appendGivenCell(childNode, step.val);
comparisons++;
statCompare.textContent = comparisons;
setStatus(
step.val + (step.target === "left" ? " ≤ " : " > ") + step.pivot +
" → goes " + step.target,
);
cell.el.classList.add("is-consumed");
return false;
} else if (step.type === "partitioned") {
clearReadPointers();
if (step.left.length === 0) addGhostCell(nodesByPath[step.path + "L"]);
if (step.right.length === 0) addGhostCell(nodesByPath[step.path + "R"]);
codePanel.highlightLine(null);
setStatus(
"Partitioned into " + step.left.length + " item(s) ≤ " + step.pivot +
" and " + step.right.length + " item(s) > " + step.pivot,
);
return false;
} else if (step.type === "combine") {
setActiveNode(step.path);
revealSorted(step.path, step.result);
codePanel.highlightLine("combine");
setStatus(
"Combining: sorted(≤) + <span class=\"hl\">" + step.pivot +
"</span> + sorted(>)",
);
return false;
} else if (step.type === "done") {
clearActiveNode();
clearReadPointers();
codePanel.highlightLine(null);
statPivot.textContent = "done";
setStatus(
'<span class="ok">Sorted</span> — ' + comparisons + " comparisons across " +
partitions + " partitions",
);
return true;
}
}
DemoEngine.createPlayer({
btnPlay: document.getElementById("btnPlay"),
btnStep: document.getElementById("btnStep"),
btnReset: document.getElementById("btnReset"),
btnShuffle: document.getElementById("btnShuffle"),
speedInput: document.getElementById("speed"),
speedValueEl: document.getElementById("speedValue"),
sizeInput: document.getElementById("size"),
sizeValueEl: document.getElementById("sizeValue"),
sizeLabel: function (n) {
return n + " items";
},
randomValues: randomValues,
onReset: function (values) {
comparisons = 0;
partitions = 0;
statCompare.textContent = "0";
statPartitions.textContent = "0";
statPivot.textContent = "–";
codePanel.highlightLine(null);
setStatus("Ready — press Play or Step");
buildTree(values);
},
createGenerator: function (values) {
return quickSortSteps(values);
},
applyStep: applyStep,
});
})();
</script>