队列的数据结构
队列是遵循FIFO(First In First Out,先进先出)原则的一组有序的项。队列从队尾添加新元素,从队首移出元素。
创建队列
function Queue(){let item = [];//向队列中添加元素this.enqueue = function(e){item.push(e)}//从队列中删除元素this.endelete = function(){item.shift()}//查看队列头元素this.front = function(){return item[0]}//检查队列是否为空this.isEpmty = function(){return item.length;}this.getItem = function(){console.log(item)}}function hotPoto(namelist){let queue = new Queue();for(let i = 0; i<namelist.length;i++){queue.enqueue(namelist[i]);}}let list = ['list1','list2','list3','list4']hotPoto(list)
