1. 程式人生 > 其它 >js中的資料結構

js中的資料結構

技術標籤:javascript

雜湊表這些就對應 用 ES6裡的map;佇列的封裝實際上也是用陣列完成的,所以佇列可以用陣列???

function Queue(){
            this.items = []
            // 方法
            Queue.prototype.enqueue = function(element){
                this.items.push(element)
            }
            Queue.prototype.dequeue= function() {
                return
this.items.shift() } Queue.prototype.front = function(){ return this.items[0] } Queue.prototype.isEmpty = function(){ return this.items.length == 0 } Queue.prototype.size = function(){ return
this.items.length } Queue.prototype.toString = function(){ var resultString = '' for(var i = 0 ; i < this.items.length ; i++){ resultString += this.items[i] + '' } return resultString }
}