Question: CSCI 2 5 8 - Lab 3 Working with Links In this lab, you will gain more experience working with a linked data structure by

CSCI 258- Lab 3
Working with Links
In this lab, you will gain more experience working with a linked data structure by adding methods to the LinkedQueue class.
Problem 1: Add the method below that prints every element in the queue, starting with the head element. The elements must all be printed on a single line.
public void printQueue(){
Problem 2: Add the method below that prints every other element in the queue, starting with the head element. You can assume there are an even number of elements in the queue. For example, if the queue contains the elements 24681012, where 2 is the head, then this method will print "2610".
public void printEveryother(){
Problem 3: Add the method below that adds the given element to the queue...except it is added as the second element after the head, not as the tail element. For example, if the queue contains 24681012, where 2 is the head, and we want to add 7, then the queue will be 274681012. Throw the NoSuchElementException if the queue is empty.
public void addSecond(E element){
Problem 4: Add the method below that reverses the elements in the queue. For example, if the queue contains the elements 24681012, then it will contain the elements 12108642 after being reversed.
public void reverseQueue(){
Problem 5: Add the method below that returns an array containing the elements that are in the stack, in the same order (where the head element will be the first element in the array). The array will be an Object array and should have the same size as the queue. The method must not make any changes to the queue. For example, if the queue contains 24681012, then this method will return the array
\table[[2,4,6,8,10,12]]
public Object[] toArray(){
 CSCI 258- Lab 3 Working with Links In this lab, you

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!