Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | 1x 1x | import { LinkedList } from './LinkedList';
/**
* FIFO queue implemented with O(1) enqueue and dequeue operations
*/
export class Queue<T> {
private _list: LinkedList<T> = new LinkedList<T>();
/**
* Peak the tip value
*/
public peak(): T {
return this._list.head && this._list.head.value;
}
/**
* Returns the length of the queue
*/
get length(): number {
return this._list.length;
}
/**
* Enqueue a value
*/
public enqueue(value: T): void {
this._list.add(value);
}
/**
* Dequeue top most value
*/
public dequeue(): T {
return this._list.remove(0);
}
}
|