队列
特点:先进先出
队列的实现
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;
}
网友评论