class CircleQueue < T > { k : number ; head : number ; tail : number ; size : number ; data : Array < T > ; constructor ( k ) { this . k = k ; this . head = - 1 ; this . tail = - 1 ; this . size = 0 ; this . data = new Array ( k ) ; } public getFront ( ) { return this . size === 0 ? - 1 : this . data [ this . head ] ; } public getRear ( ) { return this . size === 0 ? - 1 : this . data [ this . tail ] ; } public enQueue ( item ) { if ( this . size === this . k ) { return false ; } if ( this . tail === this . head && this . tail === - 1 ) { this . head ++ ; } this . tail = this . tail === this . k - 1 ? 0 : this . tail + 1 ; this . size ++ ; this . data [ this . tail ] = item ; return true ; } public deQueue ( ) { if ( this . size === 0 ) { return false ; } delete this . data [ this . head ] ; this . head = this . head === this . k - 1 ? 0 : this . head + 1 ; this . size -- ; if ( this . size === 0 ) { this . head = - 1 ; this . tail = - 1 ; } return true ; } isEmpty ( ) { return this . size === 0 ; } isFull ( ) { return this . size === this . k ; } } export default CircleQueue ;