Question: Implement the enqueue(int x), dequeue() function for Queue in Queue.java ****post screenshots please**** package ds; public class Queue { public int size; public int[] array;

Implement the enqueue(int x), dequeue() function for Queue in Queue.java

****post screenshots please****

package ds;

public class Queue {

public int size;

public int[] array;

public int head;

public int tail;

public Queue () {

size = 0;

array = null;

head = -1;

tail = 0;

}

public Queue (int _size) {

size = _size;

array = new int[size];

head = -1;

tail = 0;

}

/*

* Implement the ENQUEUE(Q, x) function

*/

public void enqueue (int x) {

}

/*

* Implement the DEQUEUE(Q) function

*/

public int dequeue () {

}

/*

* Convert queue to string in the format of #size, head, tail,

[#elements]

*/

public String toString () {

String str;

str = size + ", " + head + ", " + tail + ", [";

for (int i = head; i%size < tail; i++)

str += array[i] + ",";

str += "]";

return str;

}

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

Queue q;

q = new Queue(10);

for (int i = 0; i < 5; i++)

q.enqueue(i);

System.out.println(q.toString());

for (int i = 0; i < 2; i++)

q.dequeue();

System.out.println(q.toString());

}

}

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!