Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Java code fragment to create a queue containing the following values: Fo

ID: 3779272 • Letter: W

Question

Write a Java code fragment to create a queue containing the following values: For the following questions, assume the queue given has the name myQueue Given the initial state for myQueue: Show its final state below after the following commands have been executed: myQueue.peek(); myOueue.dequeue(); myQueue.enqueue(5.3); myQueue.enqueue(2.5); myQueue.dequeue(); Given the Initial state for myQueue: Show its final state below after the following commands have been executed: myQueue.dequeue(); myQueue.dequeue(); myQueue.dequeue();

Explanation / Answer

Answer:

5: Code

import java.util.LinkedList;

import java.util.Queue;

import java.util.Stack;

public class StackOps{

public static void main(String args[]){

Queue<Float> myQueue = new LinkedList<Float>();

myQueue.add(new Float(27.0));

myQueue.add(new Float(24.0));

myQueue.add(new Float(21.0));

myQueue.add(new Float(18.0));

myQueue.add(new Float(9.0));

myQueue.add(new Float(6.0));

myQueue.add(new Float(3.0));

System.out.print("Queue after pushing all the elements: ");

System.out.println(myQueue);

while(!s.isEmpty()){

myQueue.remove();

}

System.out.print("Queue after popping all the elements: ");

System.out.println(myQueue);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote