Question: *I have this code and keep running into errors, i will post a pic of what im getting* package com.company; public class Queue { private

*I have this code and keep running into errors, i will post a pic of what im getting*

package com.company;

public class Queue { private int QUEUE_SIZE = 5; private Object[] items; private int front, back, count;

public Queue() { items = new Object[QUEUE_SIZE]; front = 0; back = QUEUE_SIZE - 1; count = 0; }

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

public boolean isFull() { return count == QUEUE_SIZE; }

public void enqueue(Object newItem) { if (!isFull()) { back = (back + 1) % QUEUE_SIZE; items[back] = newItem; count++; return; } else { System.out.println("Queue is full. Doubling the size."); QUEUE_SIZE = (QUEUE_SIZE * 2); // double queue size not count System.out.println("New max size is: " + QUEUE_SIZE); Object[] temp = new Object[QUEUE_SIZE]; // temp array System.arraycopy(items, front, temp, front, items.length - front); // copy the elements from front index to items.length-front if (front != 0) { System.arraycopy(items, 0, temp, items.length, front); // copy the elements in the range items[0] to items[back] into the new array } items = temp; // set items to temp array back = front + count; items[back] = newItem; // set new item count++; // increment count } //System.out.println("Trying to enqueue into full queue"); }

public Object dequeue() { if (!isEmpty()) { Object queueFront = items[front]; front = (front + 1) % QUEUE_SIZE; count--; return queueFront; } else System.out.println("Trying to dequeue from empty queue"); return null; }

public void dequeueAll() { items = new Object[QUEUE_SIZE]; front = 0; back = QUEUE_SIZE - 1; count = 0; }

public Object peek() { if (!isEmpty()) { return items[front]; } else System.out.println("Trying to peek with empty queue"); return null; }

public int size() { return count; }

@Override public String toString() { String result=""; for (int i = 0; i

/* 2nd file */

package com.company;

import java.util.Stack;

public class Runner {

public static void main(String[] args) { Queue queue=new Queue(); Queue q = new Queue(); createQueue(q); System.out.println("My queue is as follows: "); printQueue(q); System.out.println("I am going to dequque one element."); q.dequeue(); System.out.println("My queue is as follows: "); printQueue(q); System.out.println("I am going to reverse my queue: "); reverseQueue(q); System.out.println("My queue is as follows: "); printQueue(q); System.out.println("I am going to enqueue 60."); q.enqueue(60); System.out.println("My queue is as follows: "); printQueue(q); System.out.println("I am going to enqueue 70."); q.enqueue(70); System.out.println("My queue is as follows: "); printQueue(q); } public static Queue createQueue(Queue q){ q.enqueue(10); q.enqueue(20); q.enqueue(30); q.enqueue(40); q.enqueue(50); return q; }

public static void printQueue(Queue q) { int s = q.size();

for(int i=0; i

*I have this code and keep running into errors, i will post

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!