-
Notifications
You must be signed in to change notification settings - Fork 4
/
queue.html
230 lines (224 loc) · 14.3 KB
/
queue.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<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>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 -->
<div class="text-center bg-secondary rounded">
LENGTH
</div>
<input type="number" id="queuelength" class="text-center" value=20
placeholder="Enter Queue Length" name="length"
onchange="circularqueue.isactive ? circularqueue.length=value-1 : queue.length=value-1;
circularqueue.isactive && circularqueue.handlengthchange()"
>
<div class="grid grid-cols gap-10 tracking-widest " id="enqueuebuttongroup">
<button class="bg-secondary rounded hover:bg-primary20 duration-70 focus:shadow-outline"
onclick=
"circularqueue.isactive ?
circularqueue.enqueue(document.getElementById('enqueue').value) :
queue.enqueue(document.getElementById('enqueue').value);">
ENQUEUE
</button>
<button class="bg-secondary rounded hover:bg-primary20 duration-70 focus:shadow-outline"
style='display:none'
onclick="queue.enqueueFront(document.getElementById('enqueue').value);" id="enqueuefrontbutton">
ENQUEUE FRONT
</button>
</div>
<input type="number" id="enqueue" 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"
>
<div class="grid grid-cols gap-10 tracking-widest " id="dequeuebuttongroup">
<button class="bg-secondary rounded hover:bg-primary20 duration-700"
onclick="circularqueue.isactive ? circularqueue.dequeue() : queue.dequeue()">
DEQUEUE
</button>
<button class="bg-secondary rounded hover:bg-primary20 duration-700"
style='display:none'
onclick="queue.dequeueRear()" id="dequeuerearbutton">
DEQUEUE REAR
</button>
</div>
<button class="bg-secondary text-red-600 rounded hover:bg-primary20 duration-700"
onclick="circularqueue.isactive ? circularqueue.reset() : queue.reset()">
RESET
</button>
</div>
</div>
<div id="queueinfo" 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="queue.detailed=false; queue.reset();circularqueue.isactive=false; circularqueue.reset(); queue.isdeque=false; queue.toggledeque();">
Linear Queue
</button>
<div class="panel ">
<p class="py-4">
A linear queue is a linear data structure that serves the request first,
which has been arrived first. It consists of data elements which are connected
in a linear fashion. It has two pointers, i.e., front and rear, where the
insertion takes place from the front end, and deletion occurs from the front end.
</p>
<br>
<p>
Time complexity:
<ul>
<li>Dequeue: O(1)</li>
<li>Enqueue: O(1)</li>
</ul>
</p>
<br>
</div>
<button class="accordion" onclick="queue.detailed=true; queue.reset(); circularqueue.isactive=false; circularqueue.reset(); queue.isdeque=false; queue.toggledeque();">
Disadvantage of Linear Queue
</button>
<div class="panel" style="height: 700px">
<div class="py-4">
<p>
In a Linear queue, once the queue is completely full,
it's not possible to insert more elements. Even if we dequeue the queue to
remove some of the elements, until the queue is reset,
no new elements can be inserted. You must be wondering why?
</p>
<br>
<p>
When we dequeue any element to remove it from the queue, we are actually moving
the front of the queue forward, thereby reducing the overall size of the queue.
And we cannot insert new elements, because the rear pointer is still at the end
of the queue.
</p>
</div>
</div>
<button class="accordion" onclick=" queue.reset(); queue.detailed=false; circularqueue.isactive=false; circularqueue.reset(); queue.isdeque=true; queue.toggledeque();">
Deque
</button>
<div class="panel">
<div class="py-4">
<p>
Deque or Double Ended Queue is a type of queue in which insertion and removal of
elements can either be performed from the front or the rear. Thus, it does not
follow FIFO rule (First In First Out).
</p>
<br>
<p>
New items can be added at either the front or the rear. Likewise, existing items
can be removed from either end. In a sense, this hybrid linear structure provides
all the capabilities of stacks and queues in a single data structure.
</p>
<br>
<p>
Time complexity:
<ul>
<li>Dequeue: O(1)</li>
<li>Enqueue: O(1)</li>
</ul>
</p>
<br>
</div>
</div>
<button class="accordion" onclick="queue.reset(); circularqueue.isactive=true; circularqueue.reset(); queue.isdeque=false; queue.toggledeque();">
Circular Queue
</button>
<div class="panel">
<div class="py-4">
<p>
A circular queue is the extended version of a regular queue where the last
element is connected to the first element. Thus forming a circle-like structure.
Circular queue representation.
The circular queue solves the major limitation of the normal queue.
</p>
<br>
<p>
The circular queue solves the major limitation of the normal queue. In a normal queue,
after a bit of insertion and deletion, there will be non-usable empty space.
</p>
<br>
<p>
Time complexity:
<ul>
<li>Dequeue: O(1)</li>
<li>Enqueue: O(1)</li>
</ul>
</p>
<br>
</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-queue" id="queueFront">
<p class="text-center">Front is -1</p>
</div>
<div class="sudo-queue" id="queueRear">
<p class="text-center">Rear is -1</p>
</div>
</div>
<div class="animation-container items-center" id="animation-container"></div>
</div>
<!--------------------------------------------------------------------------------------------------------->
</div>
</div>
</body>
<!-- PAGE SPECIFICE ANIMATIION -->
<script src="./js/datastructureControllers/queue/queue.js"></script>
<script src="./js/datastructureControllers/queue/circularqueue.js"></script>
<script type="module" defer src="./js/utils.js"></script>
</html>