import { IQueue , ITask } from "./interfaces" ; export interface ILinkNode < T > { value : T ; next : ILinkNode < T > | null ; } /**
 * 可遍历的链表类
 */ export default class LinkedQueue implements IQueue { protected _HEAD : ILinkNode < ITask > | null ; protected _END : ILinkNode < ITask > | null ; protected _LENGTH : number ; constructor ( ) { this . _HEAD = null ; this . _END = this . _HEAD ; this . _LENGTH = 0 ; } param { * } value memberOf public add ( value ) { const newLinkNode = { value , next : null , } ; this . _LENGTH ++ ; if ( this . _HEAD ) { if ( ! this . _END ) { throw new Error ( "致命错误" ) ; } this . _END . next = newLinkNode ; this . _END = newLinkNode ; } else { this . _HEAD = this . _END = newLinkNode ; } } returns returns { * } memberOf public next ( ) { const current = this . _HEAD ; if ( ! current ) { return null ; } else { this . _HEAD = current . next ; if ( ! this . _HEAD ) { this . _END = null ; } this . _LENGTH -- ; return current . value ; } } param { any } value memberOf public jump ( value ) { const newLinkNode = { value , next : null , } ; this . _LENGTH ++ ; if ( this . _HEAD ) { newLinkNode . next = this . _HEAD ; this . _HEAD = newLinkNode ; } else { this . _HEAD = this . _END = newLinkNode ; } } returns memberOf public getLength ( ) { return this . _LENGTH ; } }