Write a Java code fragment to create a queue containing the

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();

Solution

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);

}

}

 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 th

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site