package source;
public class Deque {
private int maxSize;
private int left;
private int right;
private int nItems;
private long[] myDeque;
//constructor
public Deque(int maxSize){
this.maxSize = maxSize;
this.myDeque = new long[this.maxSize];
this.nItems = 0;
this.left = this.maxSize;
this.right = -1;
}
//insert a number into left side
public void insertLeft(long n){
if(this.left==0) this.left = this.maxSize;
this.myDeque[--this.left] = n;
this.nItems++;
}
//insert a number into right side
public void insertRight(long n){
if(this.right==this.maxSize-1) this.right = -1;
this.myDeque[++this.right] = n;
this.nItems++;
}
//remove from left
public long removeLeft(){
long temp = this.myDeque[this.left++];
if(this.left==this.maxSize) this.left = 0;
this.nItems--;
return temp;
}
//remove from right
public long removeRight(){
long temp = this.myDeque[this.right--];
if(this.left==-1) this.left = this.maxSize-1;
this.nItems--;
return temp;
}
//return true if deQue is empty
public boolean isEmpty(){
return (this.nItems==0);
}
//return size of the deQue
public int size(){
return this.nItems;
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有