Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 12, Problem 11PP
Program Plan Intro
“LinkedQueue” class
Program Plan:
Filename: “LinkedQueue.java”
- Define “LinkedQueue” class.
- Declare variable for reference of first node and number of items.
- Default constructor for “LinkedQueue” class.
- Set front 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.
- Create a reference to front.
- Performs “while” loop. This loop will repeat to obtain last node.
- Compute the value of next node by calling “getNextNode()” method.
- Set the new node at last of the queue by calling “setNextNode()” method.
-
- If the queue is empty, then
- Assign the next node to “null” by using “QueueNode” class.
- Increment the number of items.
- If the queue is empty, then
-
- 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.
- Finally returns the resultant element.
-
- If the queue is empty, then returns null.
-
- Finally returns the resultant element.
- 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()”.
- 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 parameterized 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: “LinkedQueueTest.java”
- Define “LinkedQueueTest” class.
- Define main function.
- Create an object “nameQueue” for “LinkedQueue” 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
Python For this assignment, you will write a program to allow the user to store the names and phone numbers of their contacts. Create the following classes:
Contact: two attributes. One for the contact's name and the contact's phone number.
Node: two attributes: _data and _next. For use in a linked list.
ContactList: One attribute: _head, a reference to the head of an internal linked list of Node objects.
Note: self._head is an attribute of the class, so any method which updates the internal linked list can simply update the list self._head references. There is no need to return anything like we did in methods such as add_to_end in the lecture. Note also that for the same reason, we do not have to pass a reference to the head of the list to any method, because each method should already have access to the self._head attribute.
ContactList should also have the following methods:
add(name, new_number). Creates a new Node with a Contact object as its _data. The new Node is then added…
A business that sells dog food keeps information about its dog food products in a linked list. The list is named dogFoodList. (This means dogFoodList points to the first node in the list.) A node in the list contains the name of the dog food (a String), a dog food ID (also a String) and the price (a double.)
a.) Create a class for a node in the list.
b.) Use this class to write pseudocode or Java for a public method that prints the name of all dog foods in the list where the price is more than $20.00.
In c++ , write a program to create a structure of a node, create a class Linked List. Implement all operations of a linked list as member function of this class.
• create_node(int);
• insert_begin();
• insert_pos();
• insert_last();
• delete_pos();
• sort();
• search();
• update();
• reverse();
• display();
( Drop coding in words with screenshot of output as well )
Chapter 12 Solutions
Java: An Introduction to Problem Solving and Programming (7th 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 - 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 Given main() in the Inventory class, define an insertAtFront() method in the InventoryNode class that inserts items at the front of a linked list (after the dummy head node).arrow_forwardJava programarrow_forwardWrite java code for a member function insertSorted(int d) for a linked list. The function traverses the list until it finds the correct location, then it inserts a node in that location. You may use the function given the class.arrow_forward
- Given the following definition for a LinkedList: // LinkedList.h class LinkedList { public: LinkedList(); // TODO: Implement me void printEveryOther() const; private: struct Node { int data; Node* next; }; Node * head; }; // LinkedList.cpp #include "LinkedList.h" LinkedList::LinkedList() { head = nullptr; } Implement the function printEveryOther, which prints every other data value (i.e. those at the odd indices assuming 0-based indexing).arrow_forwardA double-ended queue or deque is a generalization of a stack and a queue that supports adding and removing items from either the front or the back of the data structure. This assignment has two parts: Part-1 Create a doubly linked list based DeQueDLL class that implements the DequeInterface. The class skeleton and interface are provided to you. Implement a String toString () method that creates and returns a string that correctly represents the current deque. Such a method could prove useful for testing and debugging the class and for testing and debugging applications that use the class. Assume each queued element already provides its own reasonable toString method. Part-2 Create an application program that gives a user the following three options to choose from – insert, delete, and quit. If the user selects ‘insert’, the program should accept the integer input from the user and insert it into the deque in a sorted manner. If the user selects ‘delete’, the program should…arrow_forwardPart 3: Building a Point of Sales (POS) linked list data structure. In a POS system, a transaction is based on items purchased by the customer. The following is an example of a customer transaction receipt, where the prices shown in the receipt are GST inclusive. Write a linked list classes (one class for Node and another class for List), which store the items in the transaction. Test the classes by printing the items in the linked list and show the total price of the transaction. The following listing is the sample output for your reference: ============================== BC Items Price ============================== 10 Pagoda Gnut 110g 3.49 11 Hup Seng Cream Cracker 4.19 12 Yit Poh 2n1 Kopi-o 7.28 13 Zoelife SN & Seed 5.24 14 Gatsby S/FO Wet&Hard 16.99 15 GB W/G U/Hold 150g 6.49 ============================== Total (GST Incl.) 43.68…arrow_forward
- A readinglist is a doubly linked list in which each element of the list is a book. So, you must make sure that Books are linked with the previous prev and next element. A readinglist is unsorted by default or sorted (according to title) in different context. Please pay attention to the task description below. Refer to the relevance classes for more detail information. Implement the add_book_sorted method of the ReadingList class. Assume the readinglist is sorted by title, the add_book_sorted method takes an argument new_book (a book object), it adds the new_book to the readinglist such that the readinglist remain sorted by title. For example, if the readinglist contain the following 3 books: Title: Artificial Intelligence Applications Author: Cassie Ng Published Year: 2000 Title: Python 3 Author: Jack Chan Published Year: 2016 Title: Zoo Author: Cassie Chun Published Year: 2000 If we add another book (titled "Chinese History"; author "Qin Yuan"; and published year 1989) to the…arrow_forwardC++ programming design a class to implement a sorted circular linked list. The usual operations on a circular list are:Initialize the list (to an empty state). Determine if the list is empty. Destroy the list. Print the list. Find the length of the list. Search the list for a given item. Insert an item in the list. Delete an item from the list. Copy the list. Write the definitions of the class circularLinkedList and its member functions (You may assume that the elements of the circular linked list are in ascending order). Also, write a program to test the operations of your circularLinkedList class. NOTE: The nodes for your list can be defined in either a struct or class. Each node shall store int values.arrow_forwardYou need to implement a class named "Queue" that simulates a basic queue data structure. The class should have the following methods: Enqueue(int value) - adds a new element to the end of the queue Dequeue() - removes the element from the front of the queue and returns it Peek() - returns the element from the front of the queue without removing it Count() - returns the number of elements in the queue The class should also have a property named "IsEmpty" that returns a boolean indicating whether the queue is empty or not. Constraints: The queue should be implemented using an array and the array should automatically resize when needed. All methods and properties should have a time complexity of O(1) You can write the program in C# and use the test cases to check if your implementation is correct. An example of how the class should be used: Queue myQueue = new Queue(); myQueue.Enqueue(1); myQueue.Enqueue(2); myQueue.Enqueue(3); Console.WriteLine(myQueue.Peek()); // 1…arrow_forward
- Send me your own work not AI generated response or plagiarised response. If I see these things, I'll give multiple downvotes and will definitely report.arrow_forwardDon't copy from anywhere... please fast... typed answer Assignment: Linked List of Students You have been tasked with implementing a program in Java that uses a linked list to store and manage a list of students in a class. Each student should have a name and a grade. Your program should include the following classes: Student: Represents a student in the class. Each student should have a name and a grade. Node: Represents a node in the linked list. Each node should store a reference to a student and a reference to the next node in the list. LinkedList: Represents the linked list itself. Each linked list should have a reference to the first node in the list. Your task is to implement these classes using a linked list and demonstrate their functionality by creating a console-based interface for users to interact with the system. Your program should allow users to: Add a new student to the class at the end of the list. View information about a student, including their name and grade.…arrow_forwardGive me the answer in one Visual Studio file, not Visual Studio Code - Give me full code near and simple Develop a C++ "doubly" linked list class of your own that can hold a series of signed shorts Develop the following functionality: Develop a linked list node struct/class You can use it as a subclass like in the book (Class contained inside a class) You can use it as its own separate class Your choice Maintain a private pointer to a node class pointer (head) Constructor Initialize head pointer to null Destructor Make sure to properly delete every node in your linked list push_front(value) Insert the value at the front of the linked list pop_front() Remove the node at the front of the linked list If empty, this is a no operation operator << Display the contents of the linked list just like you would print a character string operator [] Treat like an array Return the value stored in that element of the linked list If element doesn’t exist, return…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning