Question
this is a data structures course
21. (20 points) We want to define a generic class ArrayQueue, which uses a circular array. public class Array Queue< II (1) L
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the answer below, all the details are mentioned as the comments.

Answer 1:

//to save the default capacity
private static final int DEFAULT_CAPACITY = 10;
//to store the elements of the queue
private T[] queue; 
// total number of elements currently in the queue
private int size,
// front element index
private int front, 
// back element index
private int back;        

Answer 2:

//constructor  
public ArrayQueue (int initialCapacity){
   //initialization of elements
   size = 0;
   front = 0;
   rear = 0;
//creation of the array for the initialCapacity passed
   queue = (T[])(new Object[initialCapacity]);
}

Answer 3:

public T remove(){
   //get the front element
   T e = getFront();
   //free the location
   A[front%size] = null;
   //increment the front
   front++;
   //decrease the size
   size--;
   //return the element
   return e;
}

Please let us know in the comments if you face any problems.

Add a comment
Know the answer?
Add Answer to:
this is a data structures course 21. (20 points) We want to define a generic class...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ArrayQueue

    Implement the ArrayQueue classIn the ‘Queues’ lecture, review the ‘Introduce next lab’ section.  See here that we can use a circular array to implement the queue data structure.  You must write a class named ArrayQueue that does this.ArrayQueue will be a generic class, that implements our generic QueueInterface interface.  This demonstrates the Java interface feature, where we have already implemented queue dynamically, using the LinkedQueue class covered during the lecture.Many classes are given to youDownload and unzip the Circular array project from Canvas, ‘Queues’ module, Example programs.  Open the project in...

  • Write a Client class with a main method that tests the data structures as follows: For...

    Write a Client class with a main method that tests the data structures as follows: For the ArrayStack, LinkedStack, ArrayQueue and LinkedQueue: Perform a timing test for each of these data structures. Each timing test should measure in nanoseconds how long it takes to add N Integers to the structure and how long it takes to remove N Integers from the structure. N should vary from 10 to 100,000,000 increasing N by a factor of 10 for each test. Depending...

  • Question 11 (20 points) Given the class Point below, define a class Circle that represent a...

    Question 11 (20 points) Given the class Point below, define a class Circle that represent a circle with a given center and radius. The circle class should have a center attribute named center as well as a floating point radius attribute. The center is a point object, defined by the class Point. The class should also have these members: the constructor of the class, which should take parameters to initialize all attributes - a getter for center a setter for...

  • use intellij idea main java Step 3 Develop the following class: Class Name: ImprovedQueue<T> Access Modifier:...

    use intellij idea main java Step 3 Develop the following class: Class Name: ImprovedQueue<T> Access Modifier: public Implements: QueueInterface<T> Instance variables Name: front Access modifier: private Data type: Queue Node<T> Constructors: Name: ImprovedQueue Access modifier: public Parameters: none (default constructor) Task: sets the value of front to null Methods Name: isEmpty Access modifier: public Parameters: none Return type: boolean Task: returns true if the front is equal to null; otherwise return false Name: dequeue Access modifier: public Parameters: none Return...

  • Write a second constructor that could be added to the HeapPriorityQueue class. This constructor accepts an...

    Write a second constructor that could be added to the HeapPriorityQueue class. This constructor accepts an array of elements as a parameter and uses that array as the heap rather than creating a new array. Of course, the array passed in is probably not in proper heap ordering, so you must rearrange it until it is. There's a neat trick for achieving this: If you just "bubble down" all of the non-leaf nodes of the heap, starting from the last...

  • Write a second constructor that could be added to the HeapPriorityQueue class. This constructor accepts an...

    Write a second constructor that could be added to the HeapPriorityQueue class. This constructor accepts an array of elements as a parameter and uses that array as the heap rather than creating a new array. Of course, the array passed in is probably not in proper heap ordering, so you must rearrange it until it is. There's a neat trick for achieving this: If you just "bubble down" all of the non-leaf nodes of the heap, starting from the last...

  • QUEUEBOX: Using an Array of initial size of five (5) for storage, start with the following...

    QUEUEBOX: Using an Array of initial size of five (5) for storage, start with the following generic class declaration for QueueBox: public class QueueBox<E> { private E[] elements = (ED))( new Object[5]); private int front_idx = 0; private int rear_idx = 0; private int count = 0; Hint: use the count variable to keep track of how many elements are in the queue (increment count when enqueing and decrement when dequeing). Makes it a lot easier to determine if the...

  • Given a class called Student and a class called Course that contains an ArrayList of Student....

    Given a class called Student and a class called Course that contains an ArrayList of Student. Write a method called getDeansList() as described below. Refer to Student.java below to learn what methods are available. I will paste both of the simple .JAVA codes below COURSE.JAVA import java.util.*; import java.io.*; /****************************************************** * A list of students in a course *****************************************************/ public class Course{     /** collection of Students */     private ArrayList<Student> roster; /***************************************************** Constructor for objects of class Course *****************************************************/...

  • i will rate instantly. this is a data structures course 19. (12 points) IntNode class. public...

    i will rate instantly. this is a data structures course 19. (12 points) IntNode class. public class IntNode private int data; private IntNode link; public IntNode(int d, IntNode l){data = d; link = 1;} public int getData() { return data; } public void setData(int d) { data =d; } public IntNode getLink() { return link; } public void setLink(IntNode nextNode) {link = nextNode;} %3D %3D 1) Draw a picture to illustrate the nodes created by the following statement. IntNode head1...

  • and the langue is java, thx. We want to be able to run the following lines...

    and the langue is java, thx. We want to be able to run the following lines of code: ArrayList<Pokemon> party = new ArrayLis party.add(new Pikachu (); // Ash Ketch party.add(new Caterpie(); // Ash Ketch We have already defined the following abstract class: abstract class Pokemon { // abstract method public abstract void makeNoise(); // instance method public void makeSleepNoise() { System.out.println("Zzz"); However, our code won't compile, and we don't know what's wrong. TASK: Fix the bug(s) in our code. Details...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT