Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ArrayQueue<E> implements QueueInterface<E> {
- private int front = -1;
- private int rear = -1;
- private E[] array;
- private int manyItems;
- public void enqueue(E e) {
- if (rear == -1) {
- front = rear = e; // **this line gives an incompatible type error**
- } // end if
- if (rear + 1 > (array.length - 1) ) {
- E[] temp;
- temp = (E[]) new Object[array.length * 2];
- for (int i = 0; i < array.length; i++) {
- temp[i] = array[i];
- } // end for loop
- array = temp;
- array[rear + 1] = e;
- rear = rear + 1;
- } // end if
- else {
- array[rear + 1] = e;
- rear = rear + 1;
- } // end else
- } // end enqueue method
- public E dequeue() {
- if (front == -1) {
- throw new IllegalStateException("The queue is empty, cannot dequeue");
- } // end if
- E e = front; // **this line gives an incompatible type error**
- front = front + 1;
- return e;
- } // end dequeue method
- public E front() {
- if (front == -1) {
- throw new IllegalStateException("The queue is empty, cannot return front");
- } // end if
- E e = front; // **this line gives an incompatible type error**
- return e;
- } // end front method
- } // end ArrayQueue class
- E e = front;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement