Question: Choose the best method / class from the dropdown menu. 1 ) Print elements in a queue. while ( ! queue.empty ( ) ) {

Choose thebestmethod/class from the dropdown menu.
1) Print elements in a queue.
while(!queue.empty()){
// get but don't delete the element yet
Integer current = queue.blank1;
System.out.println(current);
// delete the element
queue.blank2;
}
The method inblank1should be:[ Select ]["push()", "peek()", "poll()", "get()", "offer()", "pop()", "remove()"]
The method inblank2should be:[ Select ]["pop()", "offer()", "peek()", "push()", "poll()", "remove()", "get()"]
2) Print elements in a stack.
while(!stack.isEmpty()){
// get but don't delete the element yet
Integer current = stack.blank3;
System.out.println(current);
// delete the element
stack.blank4;
}
The method inblank3should be:[ Select ]["pop()", "get()", "remove()", "poll()", "peek()", "offer()", "push()"]
The method inblank4should be:[ Select ]["poll()", "remove()", "pop()", "push()", "get()", "peek()", "offer()"]
3) To print the elements from thefirst to last, should use[ Select ]["stack", "queue"].

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 Programming Questions!