Question: by java Implement a linked list generic queue. Remember queues are first in first out (FIFO). Use the driver to then test each of the
by java
Implement a linked list generic queue. Remember queues are first in first out (FIFO). Use the driver to then test each of the methods. Simply download it and place it with the other source files.
Create a class GenLLQueue which has the following:
Internal class ListNode which contains:
Instance variable data of type T
Instance variable link of type ListNode
Default constructor that sets both instance variables to null
Instance Variables
head which is of type ListNode which points to the first element in the queue
tail which of type ListNode which points to the last element in the queue
Constructor
A default constructor that initializes head and tail to null
Methods
enqueue This method returns no value and takes a variable of type T and adds it after the tail. The moves to tail to point to the newly added element.
dequeue This method removes and returns the first element in the queue
peek This method returns the first element of the queue without removing it
showQueue Prints out the queue in order
Driver:
public class QueuesTester { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Testing Generic Linked List Queue"); System.out.println("Enqueue'ing 10 numbers 0-9"); GenLLQueue qLLInts = new GenLLQueue(); for(int i=0;i<10;i++) { qLLInts.enqueue(i); } System.out.println("Dequeue'ing all numbers and printing them out."); for(int i=0;i<10;i++) { System.out.println(qLLInts.dequeue()); } System.out.println("Testing peek"); qLLInts.enqueue(5); System.out.println(qLLInts.peek()); System.out.println("Testing show queue"); for(int i=0;i<10;i+=2) { qLLInts.enqueue(i); } qLLInts.showQueue(); } }
example output:
Testing Generic Linked List Queue
Enqueue'ing 10 numbers 0-9
Dequeue'ing all numbers and printing them out.
0
1
2
3
4
5
6
7
8
9
Testing peek
5
Testing show queue by adding all even numbers 0 to 8
5
0
2
4
6
8
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
