leetcode.com

Thoughts on implementing a custom Priority Queue in TS (opens in new tab)

Discussed on DEV

LC 1046 My two cents: Each push and pop requires a rearrangement of the existing elements, it's almost like the priority queue is a living organism which evolves / devolves it self to maintain the order of the elements. Swap, BubbleUp, & BubbleDown are the methods doing the main lifting. Here, swap is the simple swap operation const temp: T = this.heap[i]; this.heap[i] = this.heap[j]; this.heap[j] = temp The this.compare dependency injection is the soul of the code here. It is the same decidi...

Read the original article
Sign in to keep reading the full article.

Keyboard Shortcuts

Navigation

Next / previous post
j/k
Open post
oorEnter
Preview post
v

Post Actions

Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Save / unsave
s

Recommendations

Add interest / feed
Enter
Not interested
x

Go to

Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Discover
gb
Search
/

General

Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help