Queue And Priority Queue in Typescript

  1. enqueue: Add a new element at the collection.
  2. dequeue: Remove and returns the least recently-added element.
  3. peek: Retrieve the least recently-added element without removing it.
  4. isEmpty: Checks if the collection has no elements.
export class Node<T> { 
value: T;
next: Node<T>;
}
export class Queue<T> { 
private head: Node<T>;
private tail: Node<T>;

public enqueue(value: T): Node<T> { }
public dequeue(): Node<T> { }
public peek(): T { }
public isEmpty(): boolean { }
public get data(): [] { }
}
export class PriorityNode<T> { 
value: T;
priority: number;
next: PriorityNode<T>;
}
export class PriorityQueue<T> { 
private head: PriorityNode<T>;
private tail: PriorityNode<T>;
public enqueue(value: T, priority: number): PriorityNode<T> { }
public dequeue(): PriorityNode<T> {}
public peek(): T { }
public isEmpty(): boolean { }
public get data() { }
}

--

--

--

Senior Front End Software Engineer focused on Angular. Passionate about learning new skills and sharing my knowledge. Blog agdev.tech in progress.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Jump-starting Slack bot projects: bot-zero

React — you need to know

Beginner’s Guide to Debouncing vs Throttling

WebdriverIO — getting started

Closures in JavaScript Simplified!

Human-Readable Data Format

JSON Example

I made a free Gatsby + Material-UI Starter for anyone to use

20 Example FAQ Component For Website Development

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
AG Dev

AG Dev

Senior Front End Software Engineer focused on Angular. Passionate about learning new skills and sharing my knowledge. Blog agdev.tech in progress.

More from Medium

16-ElasticSearch-Logs: Just a little aggregation more to the frontend

What is Abstraction in Object Oriented Programming?

Is the experience card really that meaningful in computer programming?

Code quality: pre-commit linting