Js heap
How do I make an js heap?
What is a js heap? How do you make a js heap? This script and codes were developed by Elliot on 22 December 2022, Thursday.
Js heap - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>js heap</title>
</head>
<body> <script src="js/index.js"></script>
</body>
</html>
Js heap - Script Codes JS Codes
class Heap { constructor() { this.heapAr = [] } insert(el) { this.heapAr[this.heapAr.length] = el this.restoreInsert() } pop() { if (this.heapAr.length > 0) { const max = this.heapAr[0] this.heapAr[0] = this.heapAr[this.heapAr.length-1] this.heapAr.splice(this.heapAr.length-1, 1) this.restoreDelete() return max } throw "heap popped with no elements." } right(i) { return 2*i+2 } left(i) { return 2*i+1 } parent(i) { return Math.floor((i-1)/2) } restoreDelete() { let j = 0 while(j < this.heapAr.length) { const l = this.left(j) const r = this.right(j) let largest = j if (l < this.heapAr.length && this.heapAr[l] > this.heapAr[largest]) { largest = l } if (r < this.heapAr.length && this.heapAr[r] > this.heapAr[largest]) { largest = r } if (largest != j) { const temp = this.heapAr[j] this.heapAr[j] = this.heapAr[largest] this.heapAr[largest] = temp j = largest } else { j = this.heapAr.length } } } restoreInsert() { if (this.heapAr.length != 1) { let j = this.heapAr.length-1 while (j > 0 && this.heapAr[j] > this.heapAr[this.parent(j)]) { const temp = this.heapAr[j] this.heapAr[j] = this.heapAr[this.parent(j)] this.heapAr[this.parent(j)] = temp j = this.parent(j) } } }
}
var track = new Heap()
Developer | Elliot |
Username | vez |
Uploaded | December 22, 2022 |
Rating | 3 |
Size | 1,724 Kb |
Views | 14,168 |
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 |
Es6 style odd one out | 1,502 Kb |
Progress Scroll | 2,037 Kb |
1bit waves | 1,919 Kb |
Planet z-invert cutoff render visualized | 5,249 Kb |
Simple Collatz Generator | 1,706 Kb |
Planet z-invert render | 4,178 Kb |
Sierpinski carpet | 1,746 Kb |
Drag and drop image 1bitifier | 2,087 Kb |
Webgl sh | 2,401 Kb |
Beam button hover and split | 2,005 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 |
Sticky Navbar | Phantomesse | 5,106 Kb |
Slides-07-1 POSITION | Exhtml | 1,909 Kb |
Bootstrap 3 Price Table | Honglio | 2,655 Kb |
Chuck Norris Background | Manz | 1,967 Kb |
Css Rotating 3d cubes different speed | Dghez | 2,364 Kb |
Ball bouncing loading animation | Adam2326 | 3,144 Kb |
CSS eye follow | Pedrocampos | 2,592 Kb |
JavaScript Animation | Rcmeisty | 4,581 Kb |
About Mazano | Kiti | 2,585 Kb |
Simple Carousel Pure CSS | Dangvanthanh | 4,080 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!