色尼玛亚洲综合影院,亚洲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中利用數組實現的循環隊列代碼,轉載需保留來源!

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

主站蜘蛛池模板: 壤塘县| 沈丘县| 乌海市| 武陟县| 都兰县| 巴东县| 三门县| 漯河市| 孙吴县| 和顺县| 哈巴河县| 南和县| 凤冈县| 通榆县| 桓台县| 新和县| 江山市| 怀化市| 甘孜县| 景宁| 东台市| 吴桥县| 古交市| 尉犁县| 和政县| 陈巴尔虎旗| 宁明县| 兰州市| 高青县| 阿荣旗| 叙永县| 海伦市| 余庆县| 乐平市| 嵩明县| 昂仁县| 砀山县| 灯塔市| 牙克石市| 泗水县| 政和县|