-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpriorityqueue.html
173 lines (168 loc) · 10.1 KB
/
priorityqueue.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DSA VISUALIZATION </title>
<script src="https://cdn.tailwindcss.com"></script>
<!---------------------------TAILWIND ---------------------------------------------------------------------------->
<script src="./js/tailwindConfig.js"></script>
<link rel="stylesheet" href="./style/style.css">
</head>
<body style="background-color:var(--primary);">
<div class="container-fluid">
<div class="flex flex-row">
<!------------------------------------------------ CONTROLLER AREA ------------------------------------->
<div class="flex-intial px-3" style="border-right: 1px solid grey; height: 100vh; width: 40%;">
<!-- This example requires Tailwind CSS v2.0+ -->
<div class="back-light py-3 px-20 my-5 rounded">
<h1 class="font-thin text-lg tracking-widest text-center">
<span>PRIORITY QUEUE</span>
</h1>
</div>
<section>
<nav class="navigation">
<input id="toggle" style="border-radius:16px;" type="checkbox" checked>
<h2>SELECT DATA STRUCTURE</h2>
<ul>
<li> <a href="index.html">Home</a></li>
<li><a href="array.html">Array</a></li>
<li><a href="stack.html">Stack</a></li>
<li><a href="queue.html">Queue</a></li>
<li><a href="priorityqueue.html">Priority Queue</a></li>
<li><a href="singlylinklist.html">Singly Linked List</a></li>
<li><a href="doublylinklist.html">Doubly Linked List</a></li>
<li><a href="binary.html">Binary Search Tree</a></li>
<li><a href="search.html">Search Algorithms</a></li>
<li><a href="sort.html">Sort Algorithms</a></li>
</ul>
</nav>
<!------------------- SECTION THAT WILL BE CHANGED------------------------------------------------->
<div class="container hidden-scroll mx-2 font-sans">
<div class="flex flex-col" id="moreInfo">
<div class="mt-3 mr-4">
<button class="simulation">
Simulation Controls
<div id="enqueueinfo" class="" style="display: none;">
<span class="closebtn" onclick="this.parentElement.style.display='none';">×</span>
<p></p>
</div>
</button>
<div class="simulationpanel w-700">
<div class="grid grid-cols-2 gap-10 tracking-widest p-5">
<!-- INITIAL WORKS WILL BE ASSIGNED HERE -->
<input type="number" id="enqueue_priority" class="text-center"
placeholder="Enter priority (1 to 99)" name="priority"
min=1 max=99 onchange="value >= min ? (value <= max ? value=value : value=max) : value=min"
>
<input type="number" id="enqueue_value" class="text-center"
placeholder="Enter value (-99 to 99)" name="enqueue"
min=-99 max=99 onchange="value >= min ? (value <= max ? value=value : value=max) : value=min"
>
<button class="bg-secondary rounded hover:bg-primary20 duration-70 focus:shadow-outline"
onclick="
let v = document.getElementById('enqueue_value').value;
let p = document.getElementById('enqueue_priority').value;
sortedPriorityQueue.isSorted ? sortedPriorityQueue.enqueue(p,v) : unsortedpriorityqueue.enqueue(p,v);">
ENQUEUE
</button>
<button class="bg-secondary text-red-600 rounded hover:bg-primary20 duration-700"
onclick="sortedPriorityQueue.isSorted ? sortedPriorityQueue.randomize() : unsortedpriorityqueue.randomize()">
RANDOM ADD
</button>
<button class="bg-secondary rounded hover:bg-primary20 duration-700"
onclick="sortedPriorityQueue.isSorted ? sortedPriorityQueue.dequeue() : unsortedpriorityqueue.dequeue();">
DEQUEUE
</button>
<button class="bg-secondary text-red-600 rounded hover:bg-primary20 duration-700"
onclick="sortedPriorityQueue.isSorted ? sortedPriorityQueue.reset() : unsortedpriorityqueue.reset()">
RESET
</button>
</div>
</div>
<div id="info" class="alert items-center" style="display: none; background: coral">
<span class="closebtn" onclick="this.parentElement.style.display='none';">×</span>
<p></p>
</div>
<button class="accordion" onclick="sortedPriorityQueue.isSorted=false;">
UnSorted Priority Queue
</button>
<div class="panel ">
<p class="py-4">
An unsorted priority queue is one in which we insert at the end and remove elements
based on priority(i,e; smallest value in the queue). The unsorted priority queue
makes adding very fast - add operations are O(1), because items are just added to
the end of the list, in no particular order.
</p>
</div>
<button class="accordion" onclick="sortedPriorityQueue.isSorted=true;">
Sorted Priority Queue
</button>
<div class="panel" style="height: 700px">
<div class="py-4">
<p>
A sorted priority queue is one in which we insert at the position and remove elements
based on priority(i,e; smallest value in the queue). The sorted priority queue
makes deleting and finding minimum value very fast - delete and peek operations are O(1), because items are just deleted from
the end of the list, in no particular order.
</p>
</div>
</div>
<div class="alert items-center">
<span class="closebtn" onclick="this.parentElement.style.display='none';">×</span>
<p>Navigate through sections to change simulation.</p>
</div>
</div>
</div>
</div>
</section>
</div>
<!--------------------------------------------------------- PLAYGROUND AHEAD ------------------------------>
<div class="container grid place-items-center h-screen back-dark" style="height:100vh; width: 60%;">
<div class="grid grid-cols-2">
<div class="sudo-pqueue">
<div class="sudo-pqueue-key" style="color: white">MIN</div>
<div id="peekindex" class="sudo-pqueue-key">-</div>
<div id="peekkey" class="sudo-pqueue-key">-</div>
</div>
<div class="sudo-pqueue">
<div class="sudo-pqueue-value">LEN</div>
<div id="sizearea" class="sudo-pqueue-key">-</div>
</div>
</div>
<div class="animation-container items-center" id="animation-container"></div>
<div id='progressBar'>
<div id='played'></div>
<div style="color: #FDD741"><strong>Seek to change Speed</strong></div>
</div>
</div>
<!--------------------------------------------------------------------------------------------------------->
</div>
</div>
</body>
<!-- PAGE SPECIFICE ANIMATIION -->
<script src="./js/datastructureControllers/queue/priorityqueue/SortedPriorityQueue.js"></script>
<script src="./js/datastructureControllers/queue/priorityqueue/UnsortedPriorityQueue.js"></script>
<script type="module" defer src="./js/utils.js"></script>
<script>
var pb = document.getElementById('progressBar');
var played = document.getElementById('played');
var vidlen = 100;
pb.onclick = seek;
function seek(e) {
var pbwid = parseInt(window.getComputedStyle(pb).width);
var clickx = e.offsetX;
var perc = clickx / pbwid;
var curtime = Math.round(vidlen * perc);
if(curtime <= 100){
played.style.width = curtime + '%';
if(sortedPriorityQueue.isSorted){
sortedPriorityQueue.speed=1000 - curtime*10;
}else{
unsortedpriorityqueue.speed=1000 - curtime*10;
}
}
}
</script>
</html>