码迷,mamicode.com
首页 > 编程语言 > 详细

javaScript Queue

时间:2016-01-12 23:08:26      阅读:457      评论:0      收藏:0      [点我收藏+]

标签:

function Queue() {
var items = [];
this.enqueue = function(element) {
items.push(element)
}
this.dequeue = function(element) {
items.shift()
}
this.front = function() {
return items[0]
}
this.isEmpty = function() {
return items.length == 0
}
this.size = function() {
return items.length
}
this.printf = function() {
console.log(items.toString())
}
this.print = function() {
console.log(items.toString())
}
}
var queue = new Queue();
console.log(queue.isEmpty());
queue.enqueue(‘shidengyun‘);
queue.enqueue(‘zhujing‘);
queue.print();
console.log(queue.size());
console.log(queue.isEmpty());
queue.dequeue();
queue.print();

javaScript Queue

标签:

原文地址:http://www.cnblogs.com/shidengyun/p/5125777.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!