色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

javascript中利用數(shù)組實現(xiàn)的循環(huán)隊列代碼

//循環(huán)隊列
function CircleQueue(size){
this.initQueue(size);
}
CircleQueue.prototype = {
//初始化隊列
initQueue : function(size){
this.size = size;
this.list = new Array();
this.capacity = size + 1;
this.head = 0;
this.tail = 0;
},
//壓入隊列
enterQueue : function(ele){
if(typeof ele == "undefined" || ele == ""){
return;
}
var pos = (this.tail + 1) % this.capacity;
if(pos == this.head){//判斷隊列是否已滿
return;
}else{
this.list[this.tail] = ele;
this.tail = pos;
}
},
//從隊列中取出頭部數(shù)據(jù)
delQueue : function(){
if(this.tail == this.head){ //判斷隊列是否為空
return;
}else{
var ele = this.list[this.head];
this.head = (this.head + 1) % this.capacity;
return ele;
}
},
//查詢隊列中是否存在此元素,存在返回下標(biāo),不存在返回-1
find : function(ele){
var pos = this.head;
while(pos != this.tail){
if(this.list[pos] == ele){
return pos;
}else{
pos = (pos + 1) % this.capacity;
}
}
return -1;
},
//返回隊列中的元素個數(shù)
queueSize : function(){
return (this.tail - this.head + this.capacity) % this.capacity;
},
//清空隊列
clearQueue : function(){
this.head = 0;
this.tail = 0;
},
//判斷隊列是否為空
isEmpty : function(){
if(this.head == this.tail){
return true;
}else{
return false;
}
}
}

JavaScript技術(shù)javascript中利用數(shù)組實現(xiàn)的循環(huán)隊列代碼,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 天台县| 阿克苏市| 保德县| 龙南县| 平凉市| 互助| 东莞市| 南澳县| 靖安县| 西青区| 广元市| 新河县| 增城市| 灵川县| 通州市| 武冈市| 济宁市| 明星| 大渡口区| 和田县| 安达市| 磐安县| 邯郸县| 石林| 皋兰县| 岳阳县| 铁力市| 静宁县| 婺源县| 沁水县| 永登县| 禹城市| 荥经县| 辽宁省| 萍乡市| 南乐县| 綦江县| 米易县| 荥经县| 桐梓县| 武功县|