<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script>
//【数据结构 JavaScript版】- web前端开发精品课程【红点工场】 --javascript-- 队列概念
// 概念:
// [1,2,3,4]
// 头1
// 尾4
// equeue 入队
// dequeue 出兑
// front 查看队列头
// isEmpty 检查队列是否为空
// size 获取队列长度
var Queue = function(){
var items = [];
// 尾进队列
this.enqueue = function(element){
items.push(element);
}
// 尾出队列
this.dequeue = function(){
return items.shift();
}
// 查看队列头
this.front = function(){
return items[0];
}
// 判断队列是否为空
this.isEmpty = function(){
return items.length==0;
}
// 获取队列的长度
this.size = function(){
return items.length;
}
}
</script>
</body>
</html>