Question: 1 . Write a queue client, LineNum, that takes an integer command line argument n and prints the nth string from the first string found
Write a queue client, "LineNum," that takes an integer command line argument n and prints the nth string from the first string found on standard input. MO
Please note that you should use an object of the Queue class given in the textbook program to implement it You should add the strings inputted by the user to a queue using the enqueue method. After the user has finished inputting strings and they've been added to the queue you should remove n strings from the queue by calling the dequeue method which would also return the string that is removed from the queue n times. The string that is returned by the dequeue method when it is called the nth time should then be printed out.
Sample runs would be as follows.
java LineNum
apple
save
that
is
too
me
from the first is save
Program
public class queue
private Node first;
private Node last;
private class Node
private Item item;
private Node next;
public boolean isEmpty
return firstnull;
public void enqueueItem item
Node oldLast last;
last new Node;
last.item item;
last.next null;
if isEmpty first last;
oldLast.next last;
public Item dequeue
Item item first.item;
first first.next;
if isEmpty last null; return item;
public static void mainStringargs
queue queue new Queue;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
