链表 -> 队列
class QueueByLinkList{ constructor(){ this.queue = null } add(value){ if(!this.queue){ this.queue = { value, next: null } return } let cur = this.queue while(cur.next){ cur = cur.next } cur.next = { value, next:null } } shift(){ const value = this.queue.value this.queue = this.queue.next return value } }
数组 -> 队列
class QueueByArray { constructor(){ this.queue = [] } push(value){ this.queue.push(value) } shift(){ this.queue.shift() } }
标签:queue,cur,队列,value,next,链表,数组 From: https://www.cnblogs.com/zhenjianyu/p/17068021.html