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

javascript中利用數組實現的循環隊列代碼

//循環隊列
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;
}
},
//從隊列中取出頭部數據
delQueue : function(){
if(this.tail == this.head){ //判斷隊列是否為空
return;
}else{
var ele = this.list[this.head];
this.head = (this.head + 1) % this.capacity;
return ele;
}
},
//查詢隊列中是否存在此元素,存在返回下標,不存在返回-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;
},
//返回隊列中的元素個數
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技術javascript中利用數組實現的循環隊列代碼,轉載需保留來源!

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

主站蜘蛛池模板: 荣昌县| 同德县| 上杭县| 平舆县| 富川| 中宁县| 龙陵县| 荥阳市| 乌拉特前旗| 长沙县| 高安市| 清水河县| 闻喜县| 中西区| 辛集市| 荃湾区| 台东县| 马边| 沅陵县| 临城县| 禄丰县| 南部县| 隆尧县| 随州市| 甘肃省| 安图县| 理塘县| 外汇| 安达市| 绵阳市| 呼图壁县| 绥芬河市| 金寨县| 广西| 抚远县| 阿尔山市| 织金县| 武邑县| 奉新县| 松潘县| 师宗县|