首页 > Web开发 > 详细

js:数据结构笔记4--队列

时间:2014-10-16 10:35:53      阅读:304      评论:0      收藏:0      [点我收藏+]

队列是一种特殊的列表,数据结构为FIFO;

定义:

function Queue() {
   this.dataStore = [];
   this.enqueue = enqueue;
   this.dequeue = dequeue;
   this.front = front;
   this.back = back;
   this.length = length;
   this.toString = toString;
   this.isEmpty = isEmpty;
}
function enqueue(elem) {
   this.dataStore.push(elem);
}
function dequeue() {
   return this.dataStore.shift();
}
function front() {
   return this.dataStore[0];
}
function back() {
   return this.dataStore[this.dataStore.length - 1];
}
function toString() {
   var retStr = "";
   for(var i = 0; i < this.dataStore.length; ++i) {
      retStr += this.dataStore[i] + "\n";
   }
   return retStr;
}
function length() {
   return this.dataStore.length;
}
function isEmpty() {
   if(this.dataStore.length === 0) {
      return true;
   } else {
      return false;
   }
}

  

 

js:数据结构笔记4--队列

原文:http://www.cnblogs.com/jinkspeng/p/4028170.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!