Instructor Solutions Manual For Introduction To Java Programming And Data Structures, Comprehensive Version, 11th Edition
11th Edition
ISBN: 9780134671581
Author: Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 25.6, Problem 25.6.3CP
Explanation of Solution
“java.util.PriorityQueue” class:
This is an unbounded priority queue based on a priority heap. It does not allow null elements. In priority queue the elements are ordered according to the ordinary order.
Given statement in Listing 25.9:
- In the given statement initially create the single node tree and added to the heap.
- In every iteration, the “while” condition set the two smallest weight which are removed from the heap and are gathered to form a big tree, then the new tree is added to the heap...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Students might find it difficult to implement stack using array or linked list or both. For example, in array based implementation, students have to check for stack overflow and underflow exceptions. Also, in case of linked list based implementation, only stack underflow condition needs to be checked.
Solutions:
Students have to create class for stack related exceptions. Two different classes can be declared, one for overflow and one for underflow. Both classes need to extend the Exception class of Java.
Put stack’s push and pop methods inside a try-catch block and handle the exceptions.
It can get difficult or confusing to check all conditions of parenthesis matching. Because, when a closing parenthesis/curly brace/bracket is encountered one needs to make sure the correct type of opening parenthesis/curly brace/bracket are popped from the stack
Solutions:
Students need to write if-else if checking for each type of parenthesis/curly brace/bracket separately when an opening…
Write a Reverse Polish Notation (RPN) calculator in Java.
Write a Stack class for doubles:
constructor and push, pop, empty, peek functions.
Use an array implementation for the stack (or a linked list if you did this before class on 3/5).
If you want, you can limit the stack size to ten (HP only had three on their first attempt!), but in that case you should make your push do nothing if the stack is full. Most modern stack implementations have no arbitrary size limit.
The pop and peek methods should throw an exception if they are called on an empty stack (see code for this below).
Write a RPN class:
constructor (takes a String expression, e.g. "3 4 5 + *") and an evaluate method which returns a double ("3 4 5 + *" would evaluate to (4+5)*3=27).
Write a RPNCalculator class:
main method with whatever accouterments you see fit.
Allow the user to type in an expression, then evaluate it and repeat until they say quit.
This is in c++
Given the MileageTrackerNode class, complete main() to insert nodes into a linked list (using the InsertAfter() function). The first user-input value is the number of nodes in the linked list. Use the PrintNodeData() function to print the entire linked list. Don't print the dummy head node.
Example
input :
3
2.2
7/2/18
3.2
7/7/18
4.5
7/16/18
output:
2.2, 7/2/18
3.2, 7/7/18
4.5, 7/16/18
main.cpp:
#include "MileageTrackerNode.h"#include <string>#include <iostream>using namespace std;
int main (int argc, char* argv[]) {// References for MileageTrackerNode objectsMileageTrackerNode* headNode;MileageTrackerNode* currNode;MileageTrackerNode* lastNode;
double miles;string date;int i;
// Front of nodes listheadNode = new MileageTrackerNode();lastNode = headNode;
// TODO: Read in the number of nodes
// TODO: For the read in number of nodes, read// in data and insert into the linked list
// TODO: Call the PrintNodeData() method// to print the entire linked list
//…
Chapter 25 Solutions
Instructor Solutions Manual For Introduction To Java Programming And Data Structures, Comprehensive Version, 11th Edition
Ch. 25.2 - Prob. 25.2.1CPCh. 25.2 - Prob. 25.2.2CPCh. 25.2 - Prob. 25.2.3CPCh. 25.2 - Prob. 25.2.4CPCh. 25.2 - Prob. 25.2.5CPCh. 25.3 - Prob. 25.3.1CPCh. 25.3 - Prob. 25.3.2CPCh. 25.3 - Prob. 25.3.3CPCh. 25.3 - Prob. 25.3.4CPCh. 25.4 - Prob. 25.4.1CP
Ch. 25.4 - Prob. 25.4.2CPCh. 25.4 - Prob. 25.4.3CPCh. 25.4 - Prob. 25.4.4CPCh. 25.4 - Prob. 25.4.5CPCh. 25.5 - Prob. 25.5.1CPCh. 25.5 - Prob. 25.5.2CPCh. 25.5 - Prob. 25.5.3CPCh. 25.5 - Prob. 25.5.4CPCh. 25.5 - Prob. 25.5.5CPCh. 25.6 - Prob. 25.6.1CPCh. 25.6 - Prob. 25.6.2CPCh. 25.6 - Prob. 25.6.3CPCh. 25.6 - How do you replace lines 9499 in Listing 25.11...Ch. 25 - Prob. 25.1PECh. 25 - (Implement inorder traversal without using...Ch. 25 - (Implement preorder traversal without using...Ch. 25 - (Implement postorder traversal without using...Ch. 25 - Prob. 25.6PECh. 25 - Prob. 25.7PECh. 25 - (Implement bidirectional iterator) The...Ch. 25 - Prob. 25.9PECh. 25 - Prob. 25.10PECh. 25 - Prob. 25.11PECh. 25 - (Test BST) Design and write a complete test...Ch. 25 - (Modify BST using Comparator) Revise BST in...Ch. 25 - Prob. 25.15PECh. 25 - (Data compression: Huffman coding) Write a program...Ch. 25 - Prob. 25.17PECh. 25 - (Compress a file) Write a program that compresses...Ch. 25 - (Decompress a file) The preceding exercise...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- This is in c++ Given the MileageTrackerNode class, complete main() to insert nodes into a linked list (using the InsertAfter() function). The first user-input value is the number of nodes in the linked list. Use the PrintNodeData() function to print the entire linked list. Don't print the dummy head node. Example input : 3 2.2 7/2/18 3.2 7/7/18 4.5 7/16/18 output: 2.2, 7/2/18 3.2, 7/7/18 4.5, 7/16/18 main.cpp: #include "MileageTrackerNode.h"#include <string>#include <iostream>using namespace std; int main (int argc, char* argv[]) {// References for MileageTrackerNode objectsMileageTrackerNode* headNode;MileageTrackerNode* currNode;MileageTrackerNode* lastNode; double miles;string date;int i; // Front of nodes listheadNode = new MileageTrackerNode();lastNode = headNode; // TODO: Read in the number of nodes // TODO: For the read in number of nodes, read// in data and insert into the linked list // TODO: Call the PrintNodeData() method// to print the entire linked list //…arrow_forwardPractical:1. Write a Java code to illustrate the concept of Set, List and deque. Generate the correct output.2. Give a suitable example of Generic Classes and generate correct output.3. Write a Java code to implement the concept of vector and stack. Generate the correct output.arrow_forwarda. Write a class called hyprid that uses linked lists to represent a queue and stack. As you can recall that the only difference in between the stack and the queue is that the stack uses the addHead method to push items and the queue uses the addTail method to insert items. The class should be implemented using LinkedLists. The class should contain the following methods: a. boolean empty() to check if the underlying list is empty b. void push(int item) to add the item using addFirst c. void insert (int item) to add the item using addLast d. int remove() to remove an item from the beginning of the list e. int pop() the same as above but with name changedarrow_forward
- Implement a simple stack in java using the scenario below. A company wishes to keep track of the order in which it employed staff. Users can enter either "f" to fire, "h" to hire or "e" to end the program. When a member of staff is employed, their employee number is added to the top of a stack when someone has to be made redundant, the last person to join the company is removed from the top of the stack. Hint: Use ArrayListarrow_forwardConnect Four has a 6 x 7 board, and the goal of the game is to connect four pieces together horizontally, diagonally, or vertically. You need to make sure you handle inappropriate data, i.e. non-positive integers, and ask the user again for the correct input. You must continue to play the game, until the user no longer wants to play. Write this code using stacks and queues in C++arrow_forwardJava: Write a method/programme that will take a generic linked list and make a palindrome of the list. In a seperate test programme the user can add any elements to the generic list and then this list must be made a palindrome. The output should be the original list with the palindrome list added to this list.arrow_forward
- Change the Stack iterator function so that it throws a java.util exception right away.If the client alters the collection during iteration using push() or pop(), would there be a concurrent modification exception? b)arrow_forwardMy attempts at this kept giving me exception errors, I would like to compare and see what it should actually look like. I really need help with is, please Create a Java program that uses a stack to return a list containing all permutations of a given string, and then checks to see which ones are English words. It should read words from the input and create and check the permutations for each word. For example, there are six permutations of the letters in the string "tra": tra, rta, rat, tar, atr, art implementation should include a GetPermutations class (this is the client class, driver class, demo class or console class) and a PermutationsCalculator. the program should determine which of the permutations is an English word by looking them up in a dictionary text file (just a fe words). PermutationsCalculator class Fields: a stack for calculating the permutations; an ArrayList to hold all permutations an ArrayList to hold unique permutations. an ArrayList to hold the unique English…arrow_forwardIn C++arrow_forward
- ?? The language is c++, please take a screenshot of your output. Write the definition of the class linkedQueueType, which is derived from the class unorderedLinkedList. write a program to test various operations of this class. Following are code template. Please provide input and output screen shot. (ref:C++ by D.S. Malik. pages 495 Programming Exercise # 7) //Program to test the queue operations #include <iostream>#include "queueLinked.h" using namespace std; int main(){linkedQueueType<int> queue;linkedQueueType<int> copyQueue; int num; cout << "Queue Operations" << endl;cout << "Enter numbers ending with -999" << endl;cin >> num; while (num != -999){// queue.addQueue(num); //add an element to the queuecin >> num;} copyQueue = queue; //copy queue into copyQueue cout << "queue: ";// while (!queue.isEmptyQueue())// {// cout << queue.front() << " ";// queue.deleteQueue();// } cout << endl; // cout <<…arrow_forwardYou may do this assignment using either Java or C++. Do *not use the JDK LinkedList class or any linked list library! A linked list consists of zero or more nodes, which each contain one item of data and a link (Java reference, C++ pointer or reference) to the next node, if there is one. Linked List code is usually generic, so that you can use it to create a list of Strings, Students, Doubles, etc. For this assignment, you will write a simplified version of linked list that only can be used to create and use a list of ints and that has only a few of the functions typical of linked lists. The data element can be just an int, and the data type of the link to the next node can be just Node. You will need a reference (Java) or either a reference or a pointer (C++) to the first node, as well as one to the last node. Write a method/function that takes an in, creates a node with that int as its data value, and adds the node to the end of the list. This function will need to update the…arrow_forwardModify the iterator code in Stack to immediately throw a java.util.ConcurrentModificationException if the client modifies the collection (via push() or pop()) during iteration? b)arrow_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