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();
时间: 2024-10-11 07:26:31