Use a SinglyLinked List to implement a Queue a. Define a Queue interface. b. Define a LinkedQueue class (Node class).. c. Define a Test class to test all methods help me make a test class first code package LinkedQueue; import linkedstack.Node; public class SLinkedList { private Node head = null; private Node tail = null; private int size = 0; public SLinkedList() { head = null; tail = null; size = 0; } public int getSize() { return size; } public boolean isEmpty() { return size == 0; } public E getFirst() { if(isEmpty()) { return null; } return head.getElement(); } public E getLast() { if(isEmpty()) { return null; } return tail.getElement(); } public void addFirst(E e) { Node newest = new Node<>(e, null); newest.setNext(head); head = newest; if(getSize()==0) { tail = head; } size++; } public void addLast(E e) { Node newest = new Node<>(e, null); if(isEmpty()) { head = newest; } else { tail.setNext(newest); } tail = newest; size++; } public E removeFirst() { if (isEmpty()) { return null; } E firstE = head.getElement(); head = head.getNext(); size--; if(getSize()==0) { tail = null; } return firstE; } public void display() { if (isEmpty()) { System.out.println("Singly linked list is empty."); } else { Node temp = head; System.out.println("=============== begining of lists================"); do { System.out.println( "element =" + temp.getElement()); temp = temp.getNext(); }while (temp != null); System.out.println("============== Ending of lists================="); } } } Secound code package LinkedQueue; public class LinkedQueue implements Queue { private SLinkedList list = new SLinkedList<>(); public LinkedQueue ( ) {} public int size( ) { return list.getSize(); } public boolean isEmpty( ) { return list.isEmpty( ); } public void enqueue (E element) { list.addLast(element); } public E first() { return list.getFirst( ); } public E dequeue() { return list.removeFirst( ); } } third code package LinkedQueue; public interface Queue { int size(); boolean isEmpty( ); void enqueue(E e); E first( ); E dequeue(); }
Use a SinglyLinked List to implement a Queue
a. Define a Queue interface.
b. Define a LinkedQueue class (Node class)..
c. Define a Test class to test all methods
help me make a test class
first code
third code

The code you've provided is a Java implementation of a queue using a singly-linked list. Here's a breakdown of the code:
Queueinterface: It defines the methods that a queue should have, includingenqueue,dequeue, andisEmpty.Nodeclass: This is a simple class representing a node in the singly-linked list. Each node holds an integer value (data) and a reference to the next node in the list (next).LinkedQueueclass: It implements theQueueinterface. This class maintains a reference to theheadandtailnodes of the linked list.enqueue(int data): Adds a new node with the specified data to the end of the queue. If the queue is empty, bothheadandtailare set to the new node.dequeue(): Removes and returns the data from the front of the queue. If the queue is empty, it returns -1. If the queue becomes empty after dequeue, bothheadandtailare set to null.isEmpty(): Checks if the queue is empty by inspecting theheadreference.
Mainclass: The test class demonstrates how to use theLinkedQueue. It creates an instance ofQueueusing theLinkedQueueclass, enqueues three elements, and then dequeues and prints them in the order they were added.
Step by step
Solved in 5 steps with 2 images
