-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickSort.html
More file actions
86 lines (85 loc) · 4.22 KB
/
quickSort.html
File metadata and controls
86 lines (85 loc) · 4.22 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
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="default.css" />
<script type="text/javascript" src="array.js"></script>
</head>
<body>
<div id="head">
<h1>Quicksort</h1>
</div>
<div id="nav">
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="quickSort.html">Quick Sort</a></li>
<li><a href="selectionSort.html">Selection Sort</a></li>
<li>Binary Tree</li>
<li>algorithm</li>
<li>algorithm</li>
<li>algorithm</li>
<li>FAQ</li>
<li>Design</li>
<li>Journal</li>
<li><a href="mailto:varalgrep@yahoo.com?Subject=Contact">Contact Us</a></li>
</ul>
</div>
<div id="content">
<div id="display">
<p>
<button type="button" onclick="randomize()">Random</button>
<button type="button" onclick="runQuicksort()">Start</button>
<button type="button" onclick="pause()">Pause</button>
<span>Speed:</span>
<input id="speed" type="range" min="0" max="100" value="50" step="1" onchange="showValue(this.value, 'speedRange')" />
<span id="speedRange">50</span>
<span>Array Size:</span>
<input id ="arraySize" type ="range" min ="5" max ="30" value="15" step="1" onchange="showValue(this.value,'arraySizeRange')" />
<span id="arraySizeRange">15</span>
(to redraw array, click "randomize")
</p>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1000" height="200">
<g id="simulationArea">
</g>
</svg>
</div>
<div id = "psuedocode">
<ul type = "none">
<li id = "l0"><b>function partition</b>(<i>array</i>,<i>left</i>,<i>right</i>,<i>pivotIndex</i>)</li>
<ul type = "none">
<li id = "l1"><i>pivotValue</i> = array[<i>pivotIndex</i>]</li>
<li id = "l2"><b>swap</b> array[<i>pivotIndex</i>] and array[<i>right</i>]</li>
<li id = "l3"><i>storeIndex</i> = <i>left</i></li>
<li id = "l4"><b>for</b> <i>index</i> from <i>left</i> to <i>right</i></li>
<ul type = "none">
<li id = "l5"><b>if</b> (array[<i>index</i>] < <i>pivotValue</i>)</li>
<ul type = "none">
<li id = "l6"><b>swap</b> array[<i>index</i>] and array[<i>storeIndex</i>]</li>
<li id = "l7"><i>storeIndex</i> = <i>storeIndex</i> + 1</li>
</ul>
</ul>
<li id = "l8"><b>swap</b> array[<i>storeIndex</i>] and array[<i>right</i>]</li>
<li id = "l9"><b>return</b> <i>storeIndex</i></li>
</ul>
<li id = "l10"> <b>function quicksort</b>(<i>array</i>,<i>left</i>,<i>right</i>)</li>
<ul type = "none">
<li id = "l11"><b>if</b> (<i>left</i><<i>right</i>)</li>
<ul type = "none">
<li id = "l12">select the <i>pivotIndex</i></li>
<li id = "l13"><i>newPivotIndex</i> = partition(array,<i>left</i>,<i>right</i>,<i>pivotIndex</i>)</li>
<li id = "l14">quicksort(array, <i>left</i>,<i>newPivotIndex</i> - 1</li>
<li id = "l15">quicksort(array, <i>newPivotIndex</i>, <i>right</i>)</li>
</ul>
</ul>
</ul>
</div>
<div id = "summary">
<ol id ="summaryOL">
</ol>
</div>
</div>
</body>
</html>