标签:blog io os ar java for strong sp 数据
队列是一种特殊的列表,数据结构为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; } }
标签:blog io os ar java for strong sp 数据
原文地址:http://www.cnblogs.com/jinkspeng/p/4028170.html