Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Program to implement Queue with Links: public interface MyQueue { } public class Node [ I element; Noce next; public void enqueue (T element);
Program to implement Queue with Links: public interface MyQueue { } public class Node [ I element; Noce next; public void enqueue (T element); public I dequeue (); public I first(); public boolean isEmpty(); public int size (); public String toString(); public Node (I e) { } this.element = e; public I getElerent() { return element: } } public String toString() { return "Kode with element:" + element.toString(): import linkedlist.MyLinkedList; import linkedlist.Node; public boolean isEmpty() { public class MyLinkedList { Node front = null; // front or head of the list Node rear = null; // rear or tail of the list int size= 0; // This method is used to insert a node at the end of the list public void addLast (Node node) { // If linked list is empty, make front and rear point to the new node if (front == null) { front = node; rear node; if (list.size ()==0) return true; return false; } public int size () { return list.size(); } public String toString () { return "Queue"; } else { } } rear.next = node; rear = node; size++; } // This method is used to remove a node from the front of the list public Node removeFirst() { if (front null) return null; Node temp = front; front front.next; temp.next=null; public class MyLinkedListQueue implements MyQueue { MyLinkedList list = new MyLinkedList (); public void enqueue (I element) { list.addLast (new Node (element)); } // Implement Dequeue () and First() methods size--; if (size=0) rear = null; return temp; // This method is used to look at the front node of the list public Node first () { return front; } // This method returns the size of the list public int size () { return size; Exercise 3: In the link implementation of queue program the following code is missing. Your task is to implement these codes and write a test program to test the MyLinkedListQueue class. 1. Implement dequeue() and first() methods 2. Implement QueueEmptyException class to throw queue empty exception whenever user tries to deque an element from the empty queue. 3. Write a test application to run the MyLinkedListQueue class. Add few random Integers to the queue, check queue size and then remove elements from queue and print it on screen. Are the numbers printed in first in first out basis? 4. Using above implementation, create a queue of students (you can use Student class for it) and add five students to the queue. Then remove the students from queue and print their names on screen.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
To complete the implementation of the MyLinkedListQueue class we need to implement the deq...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started