我正在编写 Deque 以便能够从 Front 和 Rear 添加和删除......我认为我的逻辑是错误的,但我想不通!因为当我从前面插入时,它必须从后面移除,但也从前面移除。你会检查我的代码并帮助我吗?
public void insertLeft(long j)
{//have to make sure it is not full before inserting
if (!isFull())
if(left == maxSize-1)
left = -1;
queArray[++left] = j;
nItems++;
}
public long removeRight()
{
//make sure it is not empty first
if(!isEmpty())
if(right == maxSize)
right = 0;
nItems--;
long temp = queArray[right++];
// need to increment front after you remove an item
return temp;
}
public void insertRight(long i) {
if (!isFull())
if(right == maxSize-1)
right = 0;
queArray[++right] = i;
nItems++;
}
public long removeLeft(){
if (!isEmpty())
temp = queArray[++left];
if (left == maxSize-1)
left = -1;
nItems--;
return temp;
}