美文网首页
JavaScript描述数据结构之队列

JavaScript描述数据结构之队列

作者: _花 | 来源:发表于2018-09-26 17:31 被阅读0次
队列

队列

特点:先进先出

队列的实现

function Queue(){
  this.dataStore = [];
  this.enQueue = enqueue ;
  this.deQueue = dequeue;
  this.front = front;
  this.back = back;
  this.toStrig = toString;
  this.empty = empty;
}
function dequeue(){
    this.dataStore.shift();
}
function enqueue(value){
    this.dataStore.push(value);
}
function front(){
    return this.dataStore[0];
}
function back(){
    return this.dataStore[this.dataStore.length - 1];
}
function empty(){
    if(this.dataStore.length == 0){
        return true;
    }
    return false;
}

相关文章

网友评论

      本文标题:JavaScript描述数据结构之队列

      本文链接:https://www.haomeiwen.com/subject/ohrjoftx.html