Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 12, Problem 12PP
Program Plan Intro
Implementation of queue using circular linked list
Program Plan:
Filename: “CircularLinkedQueue.java”
- Define “CircularLinkedQueue” class.
- Declare variable for reference of first node, rear node and number of items.
- Default constructor for “CircularLinkedQueue” class.
- Set front and rear to “null” and count to “0”.
- Define the method “addToQueue()” with argument of “item”.
- If “front” is not equal to “null”, then
- Create a new node using “QueueNode” class.
- Set the new node as next to rear.
- Set the new node as rear.
- Set the new node at last.
- If the queue is empty, then
-
- Assign the next node to “null” by using “QueueNode” class.
- Set rear to front for single node in queue.
- Make the front as next to rear
- Increment the number of items.
- If “front” is not equal to “null”, then
- Define the method “removeFromQueue()”.
- If the queue is not empty, then get the element at front node by calling “getQueueElement()” method and eliminate the front node.
- Update the front and decrement the number of items.
- Finally returns the resultant element.
- If the queue is empty, then returns null.
- If the queue is not empty, then get the element at front node by calling “getQueueElement()” method and eliminate the front node.
- Define the method “isEmpty()”.
- This method returns “true” if the value of “count” is equal to “0”. Otherwise, returns “false”.
- Define the method “displayQueueValues()”.
- Declare a variable for node position.
- Create a reference to front.
- Performs “while” loop. This loop will repeat to display all elements in queue.
- Display the element of the queue.
- Go to the next node by using “getNextNode()” method.
Filename: “QueueNode.java”
- Define “QueueNode” class.
- Declare required variables for queue elements and next node value.
- Create default constructor for “QueueNode” class.
- Assign “null” values for queue elements and next node.
- Create the parametrized constructor for “QueueNode” class.
- Define the method “setNextNode()” which is used to set value for next node.
- Define the method “getNextNode()” which is used to returns the next node value.
- Define the method “setQueueElement()” which is used to assign value for queue elements.
- Define the method “getQueueElement()” which is used to returns queue elements.
Filename: “CircularLinkedQueueTest.java”
- Define “CircularLinkedQueueTest” class.
- Define main function.
- Create an object “nameQueue” for “CircularLinkedQueueTest” class.
- Add names to object “nameQueue” by using “addToQueue()” method.
- Call the method “displayQueueValues()” to display the elements in queue.
- Remove an element from the queue by calling the method “removeFromQueue()”.
- Display the result of whether the queue is empty or not by calling the method “isEmpty()”.
- Display the elements in queue after removing an element from queue by calling the method “displayQueueValues()”.
- Remove the elements from the queue by calling the method “removeFromQueue()”.
- Display the result of whether the queue is empty or not by calling the method “isEmpty()”.
- Define main function.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a Queue implementation that uses a circular linked list, which is the sameas a linked list except that no links are null and the value of last.next is first whenever the list is not empty. Keep only one Node instance variable
1 Implement a nested class DoubleNode for building doubly-linked lists, where each node contains a reference to the item preceding it and the item following it in the list (null if there is no such item). Then implement static methods for the following tasks: insert at the beginning, insert at the end, remove from the beginning, remove from the end, insert before a given node, insert after a given node, and remove a given node.
Java Programming language
Please help me with this. Thanks in advance.
Chapter 12 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Ch. 12.1 - Suppose aList is an object of the class...Ch. 12.1 - Prob. 2STQCh. 12.1 - Prob. 3STQCh. 12.1 - Prob. 4STQCh. 12.1 - Can you use the method add to insert an element at...Ch. 12.1 - Prob. 6STQCh. 12.1 - Prob. 7STQCh. 12.1 - If you create a list using the statement...Ch. 12.1 - Prob. 9STQCh. 12.1 - Prob. 11STQ
Ch. 12.1 - Prob. 12STQCh. 12.2 - Prob. 13STQCh. 12.2 - Prob. 14STQCh. 12.2 - Prob. 15STQCh. 12.2 - Prob. 16STQCh. 12.3 - Prob. 17STQCh. 12.3 - Prob. 18STQCh. 12.3 - Prob. 19STQCh. 12.3 - Write a definition of a method isEmpty for the...Ch. 12.3 - Prob. 21STQCh. 12.3 - Prob. 22STQCh. 12.3 - Prob. 23STQCh. 12.3 - Prob. 24STQCh. 12.3 - Redefine the method getDataAtCurrent in...Ch. 12.3 - Repeat Question 25 for the method...Ch. 12.3 - Repeat Question 25 for the method...Ch. 12.3 - Repeat Question 25 for the method...Ch. 12.4 - Revise the definition of the class ListNode in...Ch. 12.4 - Prob. 30STQCh. 12.5 - What is the purpose of the FXML file?Ch. 12.5 - Prob. 32STQCh. 12 - Repeat Exercise 2 in Chapter 7, but use an...Ch. 12 - Prob. 2ECh. 12 - Prob. 3ECh. 12 - Repeat Exercises 6 and 7 in Chapter 7, but use an...Ch. 12 - Write a static method removeDuplicates...Ch. 12 - Write a static method...Ch. 12 - Write a program that will read sentences from a...Ch. 12 - Repeat Exercise 12 in Chapter 7, but use an...Ch. 12 - Write a program that will read a text file that...Ch. 12 - Revise the class StringLinkedList in Listing 12.5...Ch. 12 - Prob. 12ECh. 12 - Write some code that will use an iterator to...Ch. 12 - Prob. 14ECh. 12 - Write some code that will use an iterator to...Ch. 12 - Prob. 17ECh. 12 - Revise the method selectionSort within the class...Ch. 12 - Repeat the previous practice program, but instead...Ch. 12 - Repeat Practice Program 1, but instead write a...Ch. 12 - Write a program that allows the user to enter an...Ch. 12 - Write a program that uses a HashMap to compute a...Ch. 12 - Write a program that creates Pet objects from data...Ch. 12 - Repeat the previous programming project, but sort...Ch. 12 - Repeat the previous programming project, but read...Ch. 12 - Prob. 9PPCh. 12 - Prob. 10PPCh. 12 - Prob. 11PPCh. 12 - Prob. 12PPCh. 12 - Prob. 13PPCh. 12 - Prob. 14PPCh. 12 - Prob. 15PP
Knowledge Booster
Similar questions
- Java Programming language Please help me with this. Thanks in advance.arrow_forwardWrite the code to delete a node in the middle of a list implemented as a linked list with the dummy node (see Exercise 3). Compare your answer with the answer to Exercise 3. Are they the same? What do you conclude? Does the dummy node simplify the operation on the list? How?arrow_forwardwrite a code in modules and also with main class to implement the operation on linked list.. (searching , traversing , updating , and inserting.) insertion will be In empty list, In front of list, In the middle of list, at the end of list. The code should be in java language and also with simple coding and explanation.arrow_forward
- Implement a priority queue (for both max and min, one time the bigger numbers should have higher priority, other time the smaller numbers should have higher priority ) in python using a linked list. The priority queue should have four functions, 1/ insert(item, priorityValue), peek(), delete(), changePriority(item, newPriority).arrow_forwardWrite a Queue implementation that uses a circular linked list, which is the sameas a linked list except that no links are null and the value of last.next is first whenever the list is not empty. Keep only one Node instance variable (last)arrow_forwardGiven the linked list data structure, implement a sub-class TSortedList that makes sure that elements are inserted and maintained in an ascending order in the list. So, given the input sequence {1,7,3,11,5}, when printing the list after inserting the last element it should print like 1, 3, 5, 7, 11. Note that with inheritance, you have to only care about the insertion situation as deletion should still be handled by the parent class.arrow_forward
- Implement a method to remove a node from the centre of a singly linked list—that is, any node other than the first and end nodes—with access to only that node.EXAMPLEThe node C from the linked list a->b->c->d->e->f should be entered.Nothing is returned as a result, although the new linked list has the shape of an a->b->d->e->farrow_forwardCreate a Queue implementation that makes use of a circular linked list, which is similar to a linked list but has the final value and no null connections.Whenever the list is not empty, next comes before first. one Node instance variable at a timearrow_forwardDevelop a program in C++ that will implement a Josephus Circle using circular linked list. There are n people standing in a circle waiting to be executed. The counting out begins at some point in the circle and proceeds around the circle in a fixed direction. In each step, a certain number of people are skipped and the next person is executed. The elimination proceeds around the circle (which is becoming smaller and smaller as the executed people are removed), until only the last person remains, who is given freedom. Given the total number of persons n and a number m which indicates that m-1 persons are skipped and mth person is killed in circle. The task is to choose the place in the initial circle so that you are the last one remaining and so survive.arrow_forward
- Develop a program in C++ that will implement a Josephus Circle using circular linked list. There are n people standing in a circle waiting to be executed. The counting out begins at some point in the circle and proceeds around the circle in a fixed direction. In each step, a certain number of people are skipped and the next person is executed. The elimination proceeds around the circle (which is becoming smaller and smaller as the executed people are removed), until only the last person remains, who is given freedom. Given the total number of persons n and a number m which indicates that m-1 persons are skipped and mth person is killed in circle. The task is to choose the place in the initial circle so that you are the last one remaining and so survive. ***Using #include <iostream>arrow_forwardImplement a function to insert a node at the end of a doubly linked list. Explain the steps involved and analyze the time complexity of your implementation.arrow_forwardI need the answer as soon as possiblearrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education