JavaScript描述数据结构之队列

队列

队列

特点:先进先出

队列的实现

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描述数据结构之队列)