import * as Events from 'events' export class Queue extends Events.EventEmitter { private q : T[] = [] constructor() { super() } isEmpty() : boolean { return this.q.length == 0 } knock() { this.emit('data') } enq(x : T) { this.q.push(x) this.emit('data') } reenq(x : T) { this.q.unshift(x) // this.emit('data') } deq() : T { let x : T = this.peek() this.q.shift() return x } peek() : T { if (this.isEmpty()) { throw new Error("queue is empty") } let x : T = this.q[0] return x } }