SHARE
TWEET

Untitled

a guest Mar 19th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class ArrayQueue<E> implements QueueInterface<E> {
  2.  
  3.    private int front = -1;
  4.    private int rear = -1;
  5.    private E[] array;
  6.    private int manyItems;
  7.  
  8.    public void enqueue(E e) {
  9.       if (rear == -1) {
  10.          front = rear = e; // **this line gives an incompatible type error**
  11.       } // end if
  12.  
  13.       if (rear + 1 > (array.length - 1) ) {
  14.          E[] temp;
  15.          temp = (E[]) new Object[array.length * 2];
  16.          for (int i = 0; i < array.length; i++) {
  17.             temp[i] = array[i];
  18.          } // end for loop
  19.          array = temp;
  20.          array[rear + 1] = e;
  21.          rear = rear + 1;
  22.       } // end if
  23.  
  24.       else {
  25.          array[rear + 1] = e;
  26.          rear = rear + 1;
  27.       } // end else
  28.  
  29.    } // end enqueue method
  30.  
  31.    public E dequeue() {
  32.       if (front == -1) {
  33.          throw new IllegalStateException("The queue is empty, cannot dequeue");
  34.       } // end if
  35.  
  36.       E e = front; // **this line gives an incompatible type error**
  37.       front = front + 1;
  38.  
  39.       return e;
  40.  
  41.    } // end dequeue method
  42.  
  43.    public E front() {
  44.       if (front == -1) {
  45.          throw new IllegalStateException("The queue is empty, cannot return front");
  46.       } // end if
  47.  
  48.       E e = front; // **this line gives an incompatible type error**
  49.  
  50.       return e;
  51.  
  52.    } // end front method
  53.  
  54. } // end ArrayQueue class
  55.      
  56. E e = front;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top