Exercise L4-1 Chapter 19 - Binary Trees Write a program to do the following: a. First define and implement a templated binary tree class, name it "binaryTreeType". Use the "binaryTreeType" example from the book for your starting point and modify it as needed. Store it as "binaryTreeType.h". b. Next define and implement a templated binary search tree class name it "binarySearch TreeType", and derive it from the "binary TreeType" class you created in step a. Store it as "binarySearchTreeType.h". c. Have your program create three instances of your " binarySearch TreeType" named T1, T2, T3. d. Do a postorder traversal of T1 and, while doing the postorder traversal, insert each node into 72. e. Do a preorder traversal of 72 and, while doing the preorder traversal, insert each node into 13. f. Do an inorder traversal of 73. g. Call the swapSub Trees() function in T3, then do an inorder traversal of T3. h. Output the heights and the number of leaves in each of the three binarySearch TreeType instances.
Exercise L4-1 Chapter 19 - Binary Trees Write a program to do the following: a. First define and implement a templated binary tree class, name it "binaryTreeType". Use the "binaryTreeType" example from the book for your starting point and modify it as needed. Store it as "binaryTreeType.h". b. Next define and implement a templated binary search tree class name it "binarySearch TreeType", and derive it from the "binary TreeType" class you created in step a. Store it as "binarySearchTreeType.h". c. Have your program create three instances of your " binarySearch TreeType" named T1, T2, T3. d. Do a postorder traversal of T1 and, while doing the postorder traversal, insert each node into 72. e. Do a preorder traversal of 72 and, while doing the preorder traversal, insert each node into 13. f. Do an inorder traversal of 73. g. Call the swapSub Trees() function in T3, then do an inorder traversal of T3. h. Output the heights and the number of leaves in each of the three binarySearch TreeType instances.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
In C++, please follow the instructions and also give a sample output of your
![Exercise L4-1 Chapter 19 - Binary Trees
Write a program to do the following:
a. First define and implement a templated binary tree class, name it "binaryTreeType". Use
the "binaryTreeType" example from the book for your starting point and modify it as needed.
Store it as "binaryTreeType.h".
b. Next define and implement a templated binary search tree class name it
"binarySearch TreeType", and derive it from the "binary TreeType" class you created in
step a. Store it as "binarySearchTreeType.h".
c.
Have your program create three instances of your " binarySearch TreeType" named T1, T2,
T3.
d. Do a postorder traversal of T1 and, while doing the postorder traversal, insert each node
into T2.
e. Do a preorder traversal of T2 and, while doing the preorder traversal, insert each node into
T3.
Do an inorder traversal of T3.
f.
g. Call the swapSub Trees() function in 73, then do an inorder traversal of T3.
h. Output the heights and the number of leaves in each of the three binarySearch TreeType
instances.
Submit only the header files (binaryTreeType.h, and binarySearch TreeType.h) and your
documentation files. The header files must include all function definitions. Validate compilation
of your header files with the following code. The test program will exercise all functions in the
classes listed above.
//Data: 65 55 22 44 61 19 90 10 78 52-999
#include <iostream>
#include "binary Search TreeType.h"
using namespace std;
int main()
{
binary Search TreeType<int> treeRoot,
int num;
cout << "Enter integers ending with -999" << endl;
cin >> num;
while (num != -999)](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F7cff8c4a-bb33-4b54-bd2d-8ccd43ef3f82%2F8d156ef0-4c7a-4406-a87b-141589de80a2%2F03pj5ai_processed.png&w=3840&q=75)
Transcribed Image Text:Exercise L4-1 Chapter 19 - Binary Trees
Write a program to do the following:
a. First define and implement a templated binary tree class, name it "binaryTreeType". Use
the "binaryTreeType" example from the book for your starting point and modify it as needed.
Store it as "binaryTreeType.h".
b. Next define and implement a templated binary search tree class name it
"binarySearch TreeType", and derive it from the "binary TreeType" class you created in
step a. Store it as "binarySearchTreeType.h".
c.
Have your program create three instances of your " binarySearch TreeType" named T1, T2,
T3.
d. Do a postorder traversal of T1 and, while doing the postorder traversal, insert each node
into T2.
e. Do a preorder traversal of T2 and, while doing the preorder traversal, insert each node into
T3.
Do an inorder traversal of T3.
f.
g. Call the swapSub Trees() function in 73, then do an inorder traversal of T3.
h. Output the heights and the number of leaves in each of the three binarySearch TreeType
instances.
Submit only the header files (binaryTreeType.h, and binarySearch TreeType.h) and your
documentation files. The header files must include all function definitions. Validate compilation
of your header files with the following code. The test program will exercise all functions in the
classes listed above.
//Data: 65 55 22 44 61 19 90 10 78 52-999
#include <iostream>
#include "binary Search TreeType.h"
using namespace std;
int main()
{
binary Search TreeType<int> treeRoot,
int num;
cout << "Enter integers ending with -999" << endl;
cin >> num;
while (num != -999)
![}
{
}
cout << endl<< "Tree nodes in inorder: ";
treeRoot.inorderTraversal();
cout << endl<<< "Tree nodes in preorder: "";
treeRoot.preorderTraversal();
cout << endl<< "Tree nodes in postorder: ";
treeRoot.postorderTraversal();
treeRoot.insert(num);
cin >> num;
cout << endl;
cout << "Tree Height: "<< treeRoot.treeHeight() << endl;
treeRoot.swapSubtrees();
return 0;
Your program output must look like the example below.
G:\Coursework/CIS 23-Data Structures and Algorithms 2020 Fall ONLINE Solutions Lab4L4-1>L4-1Soln.exe
Enter numbers ending with -999
16 08 24 04 12 20 28 02 06 10 14 18 22 26 30 01 03 05 07 09 11 13 15 17 19 21 23 25 27 29 31 -999
tree1 nodes In Inorder: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
tree1 nodes in postorder: 13257649 11 10 13 15 14 12 8 17 19 18 21 23 22 20 25 27 28 29 31 30 28 24 16
tree2 nodes in preorder: 132547 69 8 11 10 13 12 15 14 17 16 18 18 21 20 23 22 25 24 27 26 29 28 31 30
tree3 nodes In Inorder: 123456789 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
tree1 height: 5
tree1 leaves: 16
tree2 height: 16
tree2 leaves: 15
tree3 height: 16
tree3 leaves: 15
swapSubtree for tree3
tree3 nodes In Inorder: 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7654321](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F7cff8c4a-bb33-4b54-bd2d-8ccd43ef3f82%2F8d156ef0-4c7a-4406-a87b-141589de80a2%2Fy96jc17_processed.png&w=3840&q=75)
Transcribed Image Text:}
{
}
cout << endl<< "Tree nodes in inorder: ";
treeRoot.inorderTraversal();
cout << endl<<< "Tree nodes in preorder: "";
treeRoot.preorderTraversal();
cout << endl<< "Tree nodes in postorder: ";
treeRoot.postorderTraversal();
treeRoot.insert(num);
cin >> num;
cout << endl;
cout << "Tree Height: "<< treeRoot.treeHeight() << endl;
treeRoot.swapSubtrees();
return 0;
Your program output must look like the example below.
G:\Coursework/CIS 23-Data Structures and Algorithms 2020 Fall ONLINE Solutions Lab4L4-1>L4-1Soln.exe
Enter numbers ending with -999
16 08 24 04 12 20 28 02 06 10 14 18 22 26 30 01 03 05 07 09 11 13 15 17 19 21 23 25 27 29 31 -999
tree1 nodes In Inorder: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
tree1 nodes in postorder: 13257649 11 10 13 15 14 12 8 17 19 18 21 23 22 20 25 27 28 29 31 30 28 24 16
tree2 nodes in preorder: 132547 69 8 11 10 13 12 15 14 17 16 18 18 21 20 23 22 25 24 27 26 29 28 31 30
tree3 nodes In Inorder: 123456789 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
tree1 height: 5
tree1 leaves: 16
tree2 height: 16
tree2 leaves: 15
tree3 height: 16
tree3 leaves: 15
swapSubtree for tree3
tree3 nodes In Inorder: 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7654321
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
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.Recommended textbooks for you
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
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)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
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)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education