Here is my code where I'm attempting to create code for methods that will act as the deque in java I have the methods as follows:
void deque();
void addFront();
void addRear();
void RemoveFront();
void RemoveRear();
void isempty();
void size();
void displayArray();
I have already managed to make the code for add front and I was wondering if anybody of you could help me in coding for addRear()
, RemoveFront()
and also 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
}