Question: The Queue is an Abstract Data Type (ADT) that is a First In, First Out data type because the first element to be added to

 The Queue is an Abstract Data Type (ADT) that is a

The Queue is an Abstract Data Type (ADT) that is a "First In, First Out" data type because the first element to be added to it is the first one to be removed (much like a "queue", aka "line", at a grocery store) TASK: Write a class called StringQueue that the following properties: It should have a private instance variable of type LinkedList called elements that will store all the elements of the Queue It must have a no-parameter constructor that initializes the elements instance variable to an empty LinkedList It must have an instance method called enqueue that has one parameter of type String called element. It should add element to the back of the elements instance variable without returning anything It must have an instance method called peek that has no parameters. It should return the element at the front of the elements instance variable (without removing it). If no elements exist, it should return null It must have an instance method called dequeue that has no parameters. It should remove and return the element at the front of the elements instance variable. If no elements exist, it should return null It must have an instance method called size that has no parameters. It should return the number of elements currently in the elements instance variable HINT: You should be able to implement each method using just a single method call to the LinkedList instance variable Sample Input: Niema Gerald Shreeman Laura Utkrisht Sample Output: CORRECT

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!