import java.util.Scanner;
import java.util.Deque;
public class MyDeque
 {
 private int maxsize;
 private int [] queArray;
 private int front;
 private int rear;
 private int nItems;


 public MyDeque (int s)
    {
         maxsize = s;
         queArray= new int[maxsize];
         front=0;
         rear=-1;
         nItems=0;
    }





public void insertFront(int j)
    {
        if (front==0)
        front=maxsize;
        queArray[--front]=j;
        nItems++;
    }


 public void insertRear(int j)
     {
         if (rear==maxsize-1)
         rear=-1;
         queArray[++rear]=j;
         nItems++;
    }

 public int removeFront()
    {
         int temp= queArray[front++];
         if(front==maxsize)
         front=0;
         nItems--;
         return temp;
    }


 public int removeRear()
    {
         int temp =queArray[rear--];
         if (rear==-1)
         rear=maxsize-1;
         nItems--;
         return temp;
    }


 public int peekFront()
    {
         return queArray[front];
    }


 public int peekRear()
    {
         return queArray[rear];
    }


 public boolean isEmpty ()
    {
         return (nItems==0);
    }


 public boolean isFull()
    {
         return (nItems==maxsize);
    }


 public int size ()

    {
         return nItems;
    }

 /*public String toString()//return the string element
           {
                   String s = "[";
                  for(int i = front; i <=rear; i++)
                   {
                           if(i != 0)
                                   s += ", ";
                           s = s + queArray[i];
                   }
                    s +="]";
                  return s;*/
}
}

please help

what errors do you get after running the code? The toString method seems fine. If it doesn't work, then maybe the problem is in the way you put data at the queArray and the way you define the front, rear

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.