C++ How to Program (Early Objects Version)
10th Edition
ISBN: 9780134448824
Author: Paul Deitel; Harvey M. Deitel
Publisher: Pearson Education (US)
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 19, Problem 19.17E
Program Plan Intro
Program Plan:
This Program defines a Class BSTStr
Class has member functions to perform following operations.
1- Display the String Binary Tree
2- Inorder Traversal of String Tree
3- Pre Order Traversal of String Binary Tree.
4- Post Order Traversal of String Binary Tree.
Each node of tree is represented as structure
structnode { string info; structnode *left; structnode *right; }*root;
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
5. (5pts) Write a Java Method which checks whether a tree is an AVL tree.
6. (30pts): Write a Java Method to implement insertion of a node with tree rebalancing. After
inserting a node, it is necessary to check each of the node's ancestors for consistency with
the rules of AVL. For each node checked. if the balance factor remains -1, 0. or I then no
rotations are necessary. However, if the balance factor becomes 2 or 2 then the subtree
rooted at this node is unbalanced. If insertions are performed serially, after each insertion, at
most two tree rotations are needed to restore the entire tree to the rules of AVL
( Solve it by using Scanner )
Using Binary search tree write a Java program to Insert and print the element in (in-Order traversal ), then search the elements (a and z) in the tree.
(Tree height)
Define a new class named BSTWithHeight that extends BST with the following method:
/** Return the height of this binary tree */
public int height ()
Use https://liveexample.pearsoncmg.com/test/Exercise25_01.txt to test your code.
Class Name: Exercise25_01
If you get a logical or runtime error, please refer https://liveexample.pearsoncmg.com/faq.html.
Chapter 19 Solutions
C++ How to Program (Early Objects Version)
Ch. 19 - Prob. 19.6ECh. 19 - Prob. 19.7ECh. 19 - Prob. 19.8ECh. 19 - Prob. 19.9ECh. 19 - Prob. 19.10ECh. 19 - Prob. 19.11ECh. 19 - (Infix-to-Post fix conversion) Stacks are used by...Ch. 19 - Prob. 19.13ECh. 19 - Prob. 19.14ECh. 19 - Prob. 19.15E
Ch. 19 - Prob. 19.16ECh. 19 - Prob. 19.17ECh. 19 - (Duplicate Elimination) In this chapter, we saw...Ch. 19 - Prob. 19.19ECh. 19 - Prob. 19.20ECh. 19 - Prob. 19.21ECh. 19 - Prob. 19.22ECh. 19 - Prob. 19.23ECh. 19 - Prob. 19.24ECh. 19 - Prob. 19.25ECh. 19 - Prob. 19.26ECh. 19 - Prob. 19.27ECh. 19 - Prob. 19.28E
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
- Topic: Singly Linked ListImplement the following functions in C++ program. Read the question carefully. (See attached photo for reference) int count(int num) This will return the count of the instances of the element num in the list. In the linked list in removeAll method, having the method count(10) will return 3 as there are three 10's in the linked list. Additionally, you are to implement these methods: bool move(int pos1, int pos2) This method will move the element at position pos1 to the position specified as pos2 and will return true if the move is successful. This will return false if either the specified positions is invalid. In the example stated, operating the method move(1, 3) will move the 1st element and shall now become the 3rd element. The linked list shall now look like: 30 -> 40 -> 10 -> 50 int removeTail() This method will remove the last element in your linked list and return the said element. If the list is empty, return 0. You can use the…arrow_forward1001 UnaI (p E. Write a program named as ProblemE_.cpp that constructs a BST from a given postorder traversal of that tree. For example, if the given traversal is {1, 7, 5, 50, 40, 10}, then the output should be the tree shown in Problem 3. Hints: • Write a recursive function to do the followings: a) Get the last element of the array and make it root of the BST. b) Find the index i such that the value in i-1 is the first value smaller than the root. c) Recursively call a function to do the same for left subarray (1 .. i-1) and right subarray (i..size-2). i) Get the last element of right half and make it right child of the root created in step a. ii) Get the last element of left half and make it left child of the root created in step a. d) return root.arrow_forward) A singly linked list contains n - 1 strings that are binary representations of numbers from the set {0, 1,.…, n – 1} where n is an exact power of 2. However, the string corresponding to one of the numbers is missing. For example, if n = 4, the list will contain any three strings from 00, 01, 10 and 11. Note that the strings in the list may not appear in any specific order. Also note that thelength of each string is lgn, hence the time to compare two strings in O(lgn). Write an algorithmthat generates the missing string in O(n).arrow_forward
- (Circular linked lists) This chapter defined and identified various operations on a circular linked list.a. 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.)b. Write a program to test various operations of the class defined in (a).arrow_forward(Implement a doubly linked list) 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 previous node in the list, as follows:public class Node<E> { E element; Node<E> next; Node<E> previous;public Node(E e) { element = e; } }Implement a new class named TwoWayLinkedList that uses a doubly linked list to store elements. The MyLinkedList class in the text extends MyAbstractList. Define TwoWayLinkedList to extend the java.util.AbstractSequentialList class. You need to implement all the methods defined in MyLinkedList as well as the methods listIterator() and listIterator(int index). Both return an instance of java.util. ListIterator<E>. The former sets the cursor to the head of the list and the latter to the element at the specified index.arrow_forwardDon't rejectarrow_forward
- Topic: Singly Linked ListImplement the following functions in C++ program. Read the question carefully. (See attached photo for reference) void isEmpty() This method will return true if the linked list is empty, otherwise return false. void clear() This method will empty your linked list. Effectively, this should and already has been called in your destructor (i.e., the ~LinkedList() method) so that it will deallocate the nodes created first before deallocating the linked list itself.arrow_forwardComplete the TODOs in C++ 1. Implement sumNodes function which sums the data of all the nodes of the tree. (Silver Problem)2. Implement printLeafNode function which prints just the leaf nodes of thetree. (Gold Problem) (.hpp file in image) 1st code is driver.cpp #include <iostream> #include "tree.hpp" using namespace std; #define COUNT 10 int main() { Treet; t.createTree(); //cout<<t.root->data<<endl; t.print2DUtil(t.root, 0); // 1, 2, 4, 5, 3, 6, 7 cout<<"\nPreorder traversal of binary tree is \n"; t.preOrderTraverse(t.root); cout<<endl; /********************** Silver problem ***********************/ cout<<"\nSum of all the nodes in tree is: "<<t.sumNodes(t.root); cout<<endl; /********************** Gold problem ***********************/ cout<<"\nPrinting leaf nodes of the tree \n"; t.printLeafNode(t.root); cout<<"\nDeleting the tree \n"; t.deleteTree(t.root); t.root=NULL; cout<<endl; return0; } 2nd code:…arrow_forwardComplete using Standard C programming. Implement a singly linked list that performs the following: Displays the maximum value in the linked list using recursion. Displays the linked list in reverse order using recursion. Merge two single linked lists and display.arrow_forward
- (Please Help. My professor did not teach us any of this and will not answer my emails) Design a class named Queue for storing integers. Like a stack, a queue holds elements. In a stack, the elements are retreived in a last-in-first-out fashion. In a queue, the elements are retrieved in a first-in-first-out fashion. The class contains: An int[] data field named elements that stores the int values in the queue A data field named size that stores the number of elements in the queue A constructor that creates a Queue object with defult capacity 8 The method enqueue(int v) that adds v into the queue The method empty () that returns true if the queue is empty The method getSize() that returns the size of the queuearrow_forwardCourse: Data Structure and Algorithms Language: Java Kindly Answer in 1 hour. Read Carefully and give answer with all necesary details. Check the image also. Question7: Write a java/c++ code or an algorithm to solve the following problem. After that dry run and show output of algorithm using an example binary tree. Without dry run I will not accept. Write a recursive function/algorithm that finds the minimum value node from a Binary tree. (Caution: This is a simple binary tree not binary search tree i.e; tree is not in any order. So minimum node may be anywhere in tree.)arrow_forwardapartmentList is a pointer to the first node in a linked list of nodes. Use this for Parts a, b, and c. Part a. Create an inner class that will hold the following information: the apartment number of the apartment (an int), the number of bedrooms in the apartment (also an int), the current rent of the apartment (a double). Don't forget to include a field for the link! Just create the class itself and the instance variables; you don't need to put any methods into the class.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