【數據結構 JavaScript版】- web前端開發精品課程【紅點工場】 --javascript-- 隊列概念
阿新 • • 發佈:2018-12-15
== cti script brush true type b前端開發 dequeue div
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <script> //【數據結構 JavaScript版】- web前端開發精品課程【紅點工場】 --javascript-- 隊列概念 // 概念: // [1,2,3,4] // 頭1 // 尾4 // equeue 入隊 // dequeue 出兌 // front 查看隊列頭 // isEmpty 檢查隊列是否為空 // size 獲取隊列長度 var Queue = function(){ var items = []; // 尾進隊列 this.enqueue = function(element){ items.push(element); } // 尾出隊列 this.dequeue = function(){ return items.shift(); } // 查看隊列頭 this.front = function(){ return items[0]; } // 判斷隊列是否為空 this.isEmpty = function(){ return items.length==0; } // 獲取隊列的長度 this.size = function(){ return items.length; } } </script> </body> </html>
【數據結構 JavaScript版】- web前端開發精品課程【紅點工場】 --javascript-- 隊列概念