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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| Queue:function(){ this.items = []; this.pointer = 0; enqueue = (element) =>{ this.items.push(element); } enqueuePointer = (element,num) =>{ setPointer(num); this.items[this.pointer] = element; } dequeue = () =>{ if (isEmpty()) { return "列队为空"; } return this.items.shift(); } dequeueList = () =>{ if (isEmpty()) { return "列队为空"; } return this.items.pop(); } front = () =>{ if (isEmpty()) { return "列队为空"; } return this.items[0]; } isEmpty = () => { return this.items.length === 0; } size = () =>{ return this.items.length; } autoDelete = ()=>{ setInterval(()=>{ if(this.items.length > 30){ dequeueList() } },1500) } allItem = () =>{ return this.items; } clear = () =>{ this.items = []; } setPointer = (num) =>{ this.pointer = this.pointer < num ? this.pointer + 1 : 0; } return { enqueue, enqueuePointer, dequeue, dequeueList, front, isEmpty, size, clear, allItem, autoDelete } }
|