Program to implement Queue with Links: public interface MyQueue { } public class Node [ I...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Program to implement Queue with Links: public interface MyQueue<T> { } public class Node <D> [ 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<I> { Node<T> front = null; // front or head of the list Node<T> 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<I> 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<T> removeFirst() { if (front null) return null; Node<T> temp = front; front front.next; temp.next=null; public class MyLinkedListQueue<T> implements MyQueue<I> { MyLinkedList<T> list = new MyLinkedList<T> (); public void enqueue (I element) { list.addLast (new Node<T>(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<T> 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<T> 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<T> 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. Program to implement Queue with Links: public interface MyQueue<T> { } public class Node <D> [ 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<I> { Node<T> front = null; // front or head of the list Node<T> 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<I> 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<T> removeFirst() { if (front null) return null; Node<T> temp = front; front front.next; temp.next=null; public class MyLinkedListQueue<T> implements MyQueue<I> { MyLinkedList<T> list = new MyLinkedList<T> (); public void enqueue (I element) { list.addLast (new Node<T>(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<T> 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<T> 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<T> 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.
Expert Answer:
Answer rating: 100% (QA)
To complete the implementation of the MyLinkedListQueue class we need to implement the deq... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
A small sphere with mass 5.0010-7 kg and charge +5.00 C is released from rest a distance of 0.300 m above a large horizontal insulating sheet of charge that has uniform surface charge density = +8.00...
-
The MyLinkedList class used in Listing 24.6 is a one-way directional linked list that enables one-way traversal of the list. Modify the Node class to add the new data field name previous to refer to...
-
The MyLinkedList class used in Listing 24.5 is a one-way directional linked list that enables one-way traversal of the list. Modify the Node class to add the new data field name previous to refer to...
-
Listed below are selected items from the cost-of-quality (COQ) report for Watson Products for last month. Category Amount Rework ........... $ 725 Equipment maintenance ...... 1,154 Product testing...
-
An East Coast estuary has a tidal period of 12.42 h (the semidiurnal lunar tide) and tidal currents of approximately 80 cm/s. If a one-five-hundredth-scale model is constructed with tides driven by a...
-
The $40 million lottery payment that you have just won actually pays $2 million per year for 20 years. The interest rate is 8%. a. If the first payment comes in I year, what is the present value of...
-
List various types of gears.
-
Soft Sopt is a manufacturer of futon mattresses. Soft Spots mattresses are priced at $60, but competition forces the company to offer significant discounts and rebates. As a result, the average price...
-
A block of mass 2 kg is attached to a spring with a spring constant of 100 N/m. The block is released from rest and moves along a rough horizontal surface with a coefficient of friction of 0.2. How...
-
Dippin Donuts has six bakers and a bakery supervisor on each of its two shifts. Bakers working from 8am 5pm (with a 1-hour break) are paid $6.00 per hour. Bakers working the 10pm-7am shift (with a...
-
a. A partner's dependent is a 5% limited partner in a firm client. Does the parent's direct financial interest in the client impair the firm's independence? b. A partner assigned to a firm's New York...
-
JAZ Inc has invested capital of $7million, $2 million of debt (5% interest rate) and book equity of $5 million. There are 10 shareholders each owing 5,000 shares which are trading at $120/sh. JAZ...
-
Write paragraph reflecting critically on the content of the article: Why my mother can not Speak English : tone, logic, credibility, evidence, objectivity, etc., and probably connecting it to...
-
A 50 kg box is sliding at 20 m/s along a flat, frictionless surface until it reaches a hill. How far up the hill will the box slide until it stops? [Assume the hill is tall enough that the box will...
-
Each of the following statements violates at least one of the criteria for effective supporting materials discussed in this chapter. Identify the flaw (or flaws) in each statement. As Katy Perry...
-
Write an essay on hamlet act 3. "To be or not to be."That is the great question in theater, a showcase for actors and directors each wanting to put their own stamp on the greatest of roles.What is it...
-
Find the Maclaurin series for f(x) = 1+2. What is its interval of convergence?
-
Eleni Cabinet Company sold 2,200 cabinets during 2011 at $160 per cabinet. Its beginning inventory on January 1 was 130 cabinets at $56. Purchases made during the year were as follows: February . 225...
-
Are variant records a form of polymorphism? Why or why not?
-
Explain how escape analysis, mentioned briefly in Sidebar 10.3, could be used to reduce the cost of certain synchronized statements and methods in Java.
-
Consider the visibility of class members (fields and methods) in an object-oriented language, as discussed near the end of Section C 3.4.1. Describe a mechanism that could be used to check visibility...
-
One of the main fears that retail startups have is if they will be able to compete against Walmart, Home Depot, and the other big-box stores. This is a legitimate fear. Big-box stores continue to...
-
Influencer marketing is a type of marketing where companies partner with influencers, who have a significant following on social media platforms, to promote their products or services. Influencers...
-
In the summer of 2015, Stephen Kuhl and Kabeer Chopra made their way to Philadelphia to prepare for business school. It was their first semester in the Wharton MBA program. They were both in an...
Study smarter with the SolutionInn App