A typescript implementation of the Circular Queue data structure.
Circular queue is a queue structure, the main purpose of its design is to
reuse space as much as possible on the basis of ordinary queues. Circular
queues usually need to specify the maximum volume C of the collector. If the
number of elements in the queue exceeds C, only the most recent C elements
are kept in the queue. Other operations are the same as ordinary queues.
Install
-
npm
npm install --save @algorithm.ts/circular-queue
-
yarn
yarn add @algorithm.ts/circular-queue
-
deno
import { createCircularQueue } from 'https://raw.githubusercontent.com/guanghechen/algorithm.ts/main/packages/circular-queue/src/index.ts'
Usage
-
Basic:
import { createCircularQueue } from '@algorithm.ts/circular-queue'
const queue = createCircularQueue<{ name: string }>()
queue.init(100)
queue.enqueue({ name: 'alice' })
queue.enqueue({ name: 'bob' })
queue.size()
queue.front()
queue.end()
queue.dequeue()
queue.size()
queue.isEmpty()
queue.get(0)
queue.get(0, true)
queue.get(0, false)
queue.get(1)
queue.get(1, true)
queue.get(1, false)
Related