QuestionQuestion

Modify the GenericStack class provided in this unit's course content (GenericStack.java) to implement a generic queue. You may use the original source file and just make necessary changes (including the class names). The push and pop methods will need to be changed to enque (adds an element to the end of the queue) and deque (removes an element from the front of the queue). You can retain the getSize, peek, isEmpty, and toString methods from the GenericStack class; some of them will need to be tweaked, some can be used as is.

Change the "TestStack" class to "TestQueue" ; here is the main method to use in your TestQueue class which will test your GenericQueue class:


    public static void main(String[] args)
    {
       GenericQueue queue1 = new GenericQueue<>();
       queue1.enque("London");
       queue1.enque("Paris");
       queue1.enque("Berlin");
       log(queue1);
       log(queue1.deque());
       log(queue1.deque());
       log(queue1.deque());
      
       GenericQueue queue2 = new GenericQueue<>();
       queue2.enque(1);
       queue2.enque(2);
       queue2.enque(3);
       log(queue2);
       log(queue2.deque());
       log(queue2.deque());
       log(queue2.deque());   
    }
Expected Output -- note that elements are removed in the same order as they are inserted (FIFO), compared to the TestGenericStack program output which removes them in reverse order (LIFO):
queue: [London, Paris, Berlin]
London
Paris
Berlin
queue: [1, 2, 3]
1
2
3

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import java.util.LinkedList;

/**
*
* @author
*/
public class TestQueue {

    public static void main(String[] args) {
       GenericQueue queue1 = new GenericQueue<>();
       queue1.enque("London");
       queue1.enque("Paris");
       queue1.enque("Berlin");
       log(queue1);
       log(queue1.deque());
       log(queue1.deque());
       log(queue1.deque());

       GenericQueue queue2 = new GenericQueue<>();
       queue2.enque(1);...

By purchasing this solution you'll be able to access the following files:
Solution.java.

$30.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats