Constant-time Queue using Stack
How do I make an constant-time queue using stack?
What is a constant-time queue using stack? How do you make a constant-time queue using stack? This script and codes were developed by Seoh Char on 14 December 2022, Wednesday.
Constant-time Queue using Stack - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>constant-time Queue using Stack </title>
</head>
<body> <script src="js/index.js"></script>
</body>
</html>
Constant-time Queue using Stack - Script Codes JS Codes
'use strict';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Stack = function () { function Stack() { _classCallCheck(this, Stack); this._buff = []; } Stack.prototype.push = function push(data) { this._buff.push(data); return this; }; Stack.prototype.pop = function pop() { return this._buff.pop(); }; Stack.prototype.isEmpty = function isEmpty() { return this._buff.length === 0; }; return Stack;
}();
var Queue = function () { function Queue() { _classCallCheck(this, Queue); this._stack = new Stack(); this._cache = new Stack(); } Queue.prototype.enqueue = function enqueue(data) { this._stack.push(data); }; Queue.prototype.dequeue = function dequeue() { if (this._cache.isEmpty()) { this.refill(); } return this._cache.pop(); }; Queue.prototype.refill = function refill() { while (!this._stack.isEmpty()) { this._cache.push(this._stack.pop()); } }; return Queue;
}();
var q = new Queue();
q.enqueue(1);
q.enqueue(2);
q.enqueue(3);
var log = function log(line) { return document.body.innerHTML += line + '<br />';
};
log(q.dequeue());
log(q.dequeue());
log(q.dequeue());
Developer | Seoh Char |
Username | seoh |
Uploaded | December 14, 2022 |
Rating | 3 |
Size | 2,175 Kb |
Views | 4,048 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Trick of One way direction | 1,977 Kb |
Animation loop chaining | 2,325 Kb |
Trick of Switching BackgroundColor | 1,755 Kb |
A Pen by Seoh Char | 5,325 Kb |
Stopwatch using react | 4,215 Kb |
Video Capture | 2,691 Kb |
SubLayer event bubbling | 1,913 Kb |
Coverflow | 3,516 Kb |
Switch states with different options | 1,870 Kb |
Floating point issue in Framer | 2,038 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Sass Get Function | Lukewatts | 2,155 Kb |
Iron Man SVG Loading Animation | Andythayer | 3,069 Kb |
A Pen by Tosh | Panev | 2,586 Kb |
Isometric css island | Xaddict | 2,950 Kb |
ABVI Menu Discarded | Overdrivemachines | 3,607 Kb |
Cake | Kennyname | 7,220 Kb |
Confirm Close Of Foundation Reveal Modal | Winghouchan | 1,818 Kb |
Typefaces with descriptions | Megandoty | 2,944 Kb |
Hexagons | Ashmind | 4,360 Kb |
Commuter Line Tokyu 8500 | Pedox | 7,031 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!