首页 > 代码库 > js:数据结构笔记4--队列

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

队列是一种特殊的列表,数据结构为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--队列