这是我的代码,我试图为在java中充当双端队列的方法创建代码我有如下方法:
void deque();
void addFront();
void addRear();
void RemoveFront();
void RemoveRear();
void isempty();
void size();
void displayArray();
我已经设法编写了 add front 的代码,我想知道你们中是否有人可以帮助我编写代码addRear()
,RemoveFront()
还有 RemoveRear()
。
import java.util.Scanner;
public class DequeMethods implements Deque{
int array [];
int limit;
int CurrentFrontIndex=0;
int CurrentRearIndex;
Scanner in = new Scanner(System.in);
@Override
public void deque() {
// TODO Auto-generated method stub
System.out.println("input deque limit");
this.limit = in.nextInt();
array = new int [limit];
for(int x = 0; x<limit; x++){
array[x]=0;
}
}
@Override
public void addFront() {
// TODO Auto-generated method stub
boolean Itemfull= false;
for(int x=0; x<limit;x++){
if (array[x]==0){
Itemfull= false;
CurrentFrontIndex = x;
break;
}else{
Itemfull=true;}
if(Itemfull=true){
System.out.println("input int value");
int value = in.nextInt();
int y;
for(y=CurrentFrontIndex; y>0;y--){
array[y] = array [y-1];
}
array [y]=value;
}
}
}
@Override
public void addRear() {
// TODO Auto-generated method stub
}
@Override
public void RemoveFront() {
// TODO Auto-generated method stub
}
@Override
public void RemoveRear() {
// TODO Auto-generated method stub
}