SlideShare a Scribd company logo
// Complete the C++ program and implement the routines that
are not implemented #include <iostream> #include
<iomanip> #include <fstream> #include <string> #include
<vector> using namespace std; class TreeStruct; class Tree;
class Stack; class Queue; typedef TreeStruct* TreeStructPtr;
typedef Tree* TreePtr; class Stack { private:
vector<TreeStructPtr> s; public: void push(TreeStructPtr
ptr) {s.insert(s.begin(), ptr);} TreeStructPtr pop(){
TreeStructPtr ptr = s[0]; s.erase(s.begin()); return ptr;}
bool empty(){return (s.size()==0);} }; class Queue { private:
vector<TreeStructPtr> q; public: void push(TreeStructPtr
ptr) {q.push_back(ptr);} TreeStructPtr pop(){
TreeStructPtr ptr = q[0]; q.erase(q.begin()); return ptr;}
bool empty(){return (q.size()==0);} }; class TreeStruct {
public: int Number; TreeStructPtr Left; TreeStructPtr
Right; }; class Tree { public: TreeStructPtr TreeRoot;
Tree(); void InsertIntoTree(TreeStructPtr& Root, int num);
int FindMaxLen(TreeStructPtr Root); int
FindMinLen(TreeStructPtr Root); int
CountNodes(TreeStructPtr Root); void Copy(TreeStructPtr
Root1, TreeStructPtr& Root2); //copies one tree into another
bool Search(TreeStructPtr Root, int n); void
PrintInOrderTree(TreeStructPtr Root); void
PrintPreOrderTree(TreeStructPtr Root); void
PrintPostOrderTree(TreeStructPtr Root); void
PrintPreOrderTreeWithStack(TreeStructPtr Root); void
PrintBreadthFirstWithQueue(TreeStructPtr Root); }; // ----------
------------------------------------------------------ // tree
constructor Tree::Tree() { TreeRoot = NULL; } //----------------
------------------------------------------------ void
Copy(TreeStructPtr Root1, TreeStructPtr& Root2) //copies one
tree into another { } //----------------------------------------------
------------------ // Inserting into the tree using recursion void
Tree::InsertIntoTree(TreeStructPtr& Root, int x) { } //----------
------------------------------------------------------ int
Tree::FindMaxLen(TreeStructPtr Root) { return 0; } // ----
------------------------------------------------------------ int
Tree::FindMinLen(TreeStructPtr Root) { if (Root==NULL)
return(0); else if (Root->Right==NULL)
return(1+FindMinLen(Root->Left)); else if (Root-
>Left==NULL) return(1+FindMinLen(Root->Right)); else {
int CountLeft = 1 + FindMinLen(Root->Left); int
CountRight = 1 + FindMinLen(Root->Right); if
(CountLeft < CountRight) return(CountLeft);
else return(CountRight); } } //-------------------------
--------------------------------------- int
Tree::CountNodes(TreeStructPtr Root) { return 0; } //-----
----------------------------------------------------------- bool
Tree::Search(TreeStructPtr Root, int n) { return " "; } //-
--------------------------------------------------------------- void
Tree::PrintInOrderTree(TreeStructPtr Root) { } //-----------------
----------------------------------------------- void
Tree::PrintPreOrderTree(TreeStructPtr Root) { } // ----------------
------------------------------------------------ void
Tree::PrintPostOrderTree(TreeStructPtr Root) { } //--------------
-------------------------------------------------- void
Tree::PrintPreOrderTreeWithStack(TreeStructPtr Root) {
Stack stk; TreeStructPtr p = Root; if (p != NULL)
{ stk.push(p); while (!stk.empty())
{ p = stk.pop();
cout << p->Number << "-->"; if (p->Right !=
NULL) stk.push(p->Right);
if (p->Left != NULL) stk.push(p->Left);
} } } //------------------------------------------------------------
---- void Tree::PrintBreadthFirstWithQueue(TreeStructPtr Root)
{ } //----------------------------------------------------------------
void main() { Tree t; t.InsertIntoTree(t.TreeRoot, 15);
t.InsertIntoTree(t.TreeRoot, 20); t.InsertIntoTree(t.TreeRoot,
10); t.InsertIntoTree(t.TreeRoot, 8);
t.InsertIntoTree(t.TreeRoot, 9); t.InsertIntoTree(t.TreeRoot,
17); t.InsertIntoTree(t.TreeRoot, 21);
t.InsertIntoTree(t.TreeRoot, 22); t.InsertIntoTree(t.TreeRoot,
23); t.InsertIntoTree(t.TreeRoot, 24);
t.InsertIntoTree(t.TreeRoot, 25); t.InsertIntoTree(t.TreeRoot,
26); t.InsertIntoTree(t.TreeRoot, 11); cout << " Printing Pre
Order " << endl; t.PrintPreOrderTree(t.TreeRoot); cout << "
-----------------------------------------------" << endl; getchar();
cout << "Printing Post Order " << endl;
t.PrintPostOrderTree(t.TreeRoot); cout << " --------------------
---------------------------" << endl; getchar(); cout <<
"Printing In Order " << endl; t.PrintInOrderTree(t.TreeRoot);
cout << " -----------------------------------------------" << endl;
getchar(); cout << boolalpha << endl << endl; cout << "
Searching 30: " << t.Search(t.TreeRoot, 30) << endl; cout <<
" Searching 8: " << t.Search(t.TreeRoot, 8) << endl; cout <<
" Searching 10: " << t.Search(t.TreeRoot, 10) << endl; cout
<< "-------------------------------------------" << endl; getchar();
cout << "Printing Pre Order with Stack " << endl;
t.PrintPreOrderTreeWithStack(t.TreeRoot); cout << " ---------
--------------------------------------" << endl; getchar(); cout <<
"Printing level by level BreathFirst Traversal " << endl;
t.PrintBreadthFirstWithQueue(t.TreeRoot); cout << " ----------
-------------------------------------" << endl; getchar(); cout <<
endl; int MaxLen = t.FindMaxLen(t.TreeRoot); int MinLen =
t.FindMinLen(t.TreeRoot); int TotalNodes =
t.CountNodes(t.TreeRoot); cout << "Max is " << MaxLen <<
endl; cout << "Min is " << MinLen << endl; cout << "Num
of Nodes is " << TotalNodes << endl; cout << "-----------------
------------------------------" << endl; getchar(); Tree t2;
Copy(t.TreeRoot, t2.TreeRoot); cout << "Printing In Order the
copy of the tree" << endl; t2.PrintInOrderTree(t2.TreeRoot);
cout << " -----------------------------------------------" << endl;
} //---------------------------------------------------------------- /*
Your output should look like the foolowing Printing Pre Order
15-->10-->8-->9-->11-->20-->17-->21-->22-->23-->24-->25--
>26--> ----------------------------------------------- Printing Post
Order 9-->8-->11-->10-->17-->26-->25-->24-->23-->22-->21--
>20-->15--> ----------------------------------------------- Printing
In Order 8-->9-->10-->11-->15-->17-->20-->21-->22-->23--
>24-->25-->26--> -----------------------------------------------
Searching 30: false Searching 8: true Searching 10: true -------
------------------------------------ Printing Pre Order with Stack
15-->10-->8-->9-->11-->20-->17-->21-->22-->23-->24-->25--
>26--> ----------------------------------------------- Printing level
by level BreathFirst Traversal 15-->10-->20-->8-->11-->17--
>21-->9-->22-->23-->24-->25-->26--> -----------------------------
------------------ Max is 8 Min is 3 Num of Nodes is 13 ---------
-------------------------------------- Printing In Order the copy of
the tree 8-->9-->10-->11-->15-->17-->20-->21-->22-->23-->24-
->25-->26--> ----------------------------------------------- Press any
key to continue */
Solution
Implemented the following 4 functions
void Tree::InsertIntoTree(TreeStructPtr& Root, int x) {
if (Root == NULL) {
TreeStructPtr node = new TreeStruct();
node->Number = x;
node->Left = NULL;
node->Right = NULL;
Root = node;
} else {
if (x <= Root->Number) {
if (Root->Left != NULL)
InsertIntoTree(Root->Left, x);
else {
TreeStructPtr node = new TreeStruct();
node->Number = x;
node->Left = NULL;
node->Right = NULL;
Root->Left = node;
}
} else {
if (Root->Right != NULL)
InsertIntoTree(Root->Right, x);
else {
TreeStructPtr node = new TreeStruct();
node->Number = x;
node->Left = NULL;
node->Right = NULL;
Root->Right = node;
}
}
}
}
//----------------------------------------------------------------
void Tree::PrintInOrderTree(TreeStructPtr Root) {
if (Root != NULL) {
PrintInOrderTree(Root->Left);
cout << Root->Number << "->";
PrintInOrderTree(Root->Right);
}
}
//----------------------------------------------------------------
void Tree::PrintPreOrderTree(TreeStructPtr Root) {
if (Root != NULL) {
cout << Root->Number << "->";
PrintPreOrderTree(Root->Left);
PrintPreOrderTree(Root->Right);
}
}
//----------------------------------------------------------------
void Tree::PrintPostOrderTree(TreeStructPtr Root) {
if (Root != NULL) {
PrintPostOrderTree(Root->Left);
PrintPostOrderTree(Root->Right);
cout << Root->Number << "->";
}
}
--output with your main code for these 4 methods---------------
Printing Pre Order
15->10->8->9->11->20->17->21->22->23->24->25->26->
Printing Post Order
9->8->11->10->17->26->25->24->23->22->21->20->15->
Printing In Order
8->9->10->11->15->17->20->21->22->23->24->25->26->

More Related Content

Similar to Complete the C++ program and implement the routines that are n.docx

RightTrianglerightTriangle.cppRightTrianglerightTriangle.cpp.docx
RightTrianglerightTriangle.cppRightTrianglerightTriangle.cpp.docxRightTrianglerightTriangle.cppRightTrianglerightTriangle.cpp.docx
RightTrianglerightTriangle.cppRightTrianglerightTriangle.cpp.docx
joellemurphey
 
I just need code for processQueue function using iterators from the .pdf
I just need code for processQueue function using iterators from the .pdfI just need code for processQueue function using iterators from the .pdf
I just need code for processQueue function using iterators from the .pdf
allurafashions98
 
Using C++I keep getting messagehead does not name a type.pdf
Using C++I keep getting messagehead does not name a type.pdfUsing C++I keep getting messagehead does not name a type.pdf
Using C++I keep getting messagehead does not name a type.pdf
alokkesh1
 
Were writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdfWere writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdf
fsenterprises
 
complete the following functions in c++ singleRotation putNo.pdf
complete the following functions in c++ singleRotation putNo.pdfcomplete the following functions in c++ singleRotation putNo.pdf
complete the following functions in c++ singleRotation putNo.pdf
abbecindia
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
michardsonkhaicarr37
 
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
Adamq0DJonese
 
Notes for SQLite3 Usage
Notes for SQLite3 UsageNotes for SQLite3 Usage
Notes for SQLite3 Usage
William Lee
 
Start with the inclusion of libraries#include iostream .docx
 Start with the inclusion of libraries#include iostream .docx Start with the inclusion of libraries#include iostream .docx
Start with the inclusion of libraries#include iostream .docx
MARRY7
 
Memory Manglement in Raku
Memory Manglement in RakuMemory Manglement in Raku
Memory Manglement in Raku
Workhorse Computing
 
Binary Tree in C++ coding in the data structure
Binary Tree in C++ coding in the data structureBinary Tree in C++ coding in the data structure
Binary Tree in C++ coding in the data structure
ZarghamullahShah
 
(1)Objective Binary Search Tree traversal (2 points)Use traversal.pdf
(1)Objective Binary Search Tree traversal (2 points)Use traversal.pdf(1)Objective Binary Search Tree traversal (2 points)Use traversal.pdf
(1)Objective Binary Search Tree traversal (2 points)Use traversal.pdf
arihantmobileselepun
 
Can you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdfCan you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdf
aksachdevahosymills
 
Need help implementing the skeleton code below, I have provided the .pdf
Need help implementing the skeleton code below, I have provided the .pdfNeed help implementing the skeleton code below, I have provided the .pdf
Need help implementing the skeleton code below, I have provided the .pdf
ezzi552
 
Lab08Lab08.cppLab08Lab08.cpp.docx
Lab08Lab08.cppLab08Lab08.cpp.docxLab08Lab08.cppLab08Lab08.cpp.docx
Lab08Lab08.cppLab08Lab08.cpp.docx
DIPESH30
 
Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++
Yandex
 
Need help with the TODO's (DONE IN C++) #pragma once #include -funct.pdf
Need help with the TODO's (DONE IN C++) #pragma once   #include -funct.pdfNeed help with the TODO's (DONE IN C++) #pragma once   #include -funct.pdf
Need help with the TODO's (DONE IN C++) #pragma once #include -funct.pdf
actexerode
 
Please read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdfPlease read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdf
shanki7
 
C++ extension methods
C++ extension methodsC++ extension methods
C++ extension methods
phil_nash
 
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdfC++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
feelinggift
 

Similar to Complete the C++ program and implement the routines that are n.docx (20)

RightTrianglerightTriangle.cppRightTrianglerightTriangle.cpp.docx
RightTrianglerightTriangle.cppRightTrianglerightTriangle.cpp.docxRightTrianglerightTriangle.cppRightTrianglerightTriangle.cpp.docx
RightTrianglerightTriangle.cppRightTrianglerightTriangle.cpp.docx
 
I just need code for processQueue function using iterators from the .pdf
I just need code for processQueue function using iterators from the .pdfI just need code for processQueue function using iterators from the .pdf
I just need code for processQueue function using iterators from the .pdf
 
Using C++I keep getting messagehead does not name a type.pdf
Using C++I keep getting messagehead does not name a type.pdfUsing C++I keep getting messagehead does not name a type.pdf
Using C++I keep getting messagehead does not name a type.pdf
 
Were writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdfWere writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdf
 
complete the following functions in c++ singleRotation putNo.pdf
complete the following functions in c++ singleRotation putNo.pdfcomplete the following functions in c++ singleRotation putNo.pdf
complete the following functions in c++ singleRotation putNo.pdf
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
 
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
 
Notes for SQLite3 Usage
Notes for SQLite3 UsageNotes for SQLite3 Usage
Notes for SQLite3 Usage
 
Start with the inclusion of libraries#include iostream .docx
 Start with the inclusion of libraries#include iostream .docx Start with the inclusion of libraries#include iostream .docx
Start with the inclusion of libraries#include iostream .docx
 
Memory Manglement in Raku
Memory Manglement in RakuMemory Manglement in Raku
Memory Manglement in Raku
 
Binary Tree in C++ coding in the data structure
Binary Tree in C++ coding in the data structureBinary Tree in C++ coding in the data structure
Binary Tree in C++ coding in the data structure
 
(1)Objective Binary Search Tree traversal (2 points)Use traversal.pdf
(1)Objective Binary Search Tree traversal (2 points)Use traversal.pdf(1)Objective Binary Search Tree traversal (2 points)Use traversal.pdf
(1)Objective Binary Search Tree traversal (2 points)Use traversal.pdf
 
Can you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdfCan you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdf
 
Need help implementing the skeleton code below, I have provided the .pdf
Need help implementing the skeleton code below, I have provided the .pdfNeed help implementing the skeleton code below, I have provided the .pdf
Need help implementing the skeleton code below, I have provided the .pdf
 
Lab08Lab08.cppLab08Lab08.cpp.docx
Lab08Lab08.cppLab08Lab08.cpp.docxLab08Lab08.cppLab08Lab08.cpp.docx
Lab08Lab08.cppLab08Lab08.cpp.docx
 
Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++
 
Need help with the TODO's (DONE IN C++) #pragma once #include -funct.pdf
Need help with the TODO's (DONE IN C++) #pragma once   #include -funct.pdfNeed help with the TODO's (DONE IN C++) #pragma once   #include -funct.pdf
Need help with the TODO's (DONE IN C++) #pragma once #include -funct.pdf
 
Please read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdfPlease read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdf
 
C++ extension methods
C++ extension methodsC++ extension methods
C++ extension methods
 
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdfC++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
 

More from ajoy21

Please complete the assignment listed below.Define and explain, us.docx
Please complete the assignment listed below.Define and explain, us.docxPlease complete the assignment listed below.Define and explain, us.docx
Please complete the assignment listed below.Define and explain, us.docx
ajoy21
 
Please cite sources for each question. Do not use the same sources f.docx
Please cite sources for each question. Do not use the same sources f.docxPlease cite sources for each question. Do not use the same sources f.docx
Please cite sources for each question. Do not use the same sources f.docx
ajoy21
 
Please choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docxPlease choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docx
ajoy21
 
Please check the attachment for my paper.Please add citations to a.docx
Please check the attachment for my paper.Please add citations to a.docxPlease check the attachment for my paper.Please add citations to a.docx
Please check the attachment for my paper.Please add citations to a.docx
ajoy21
 
Please answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docxPlease answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docx
ajoy21
 
Please attach Non-nursing theorist summaries.JigsawExecutive .docx
Please attach Non-nursing theorist summaries.JigsawExecutive .docxPlease attach Non-nursing theorist summaries.JigsawExecutive .docx
Please attach Non-nursing theorist summaries.JigsawExecutive .docx
ajoy21
 
Please answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docxPlease answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docx
ajoy21
 
Please answer the following questions. Please cite your references..docx
Please answer the following questions. Please cite your references..docxPlease answer the following questions. Please cite your references..docx
Please answer the following questions. Please cite your references..docx
ajoy21
 
Please answer the following questions.1.      1.  Are you or.docx
Please answer the following questions.1.      1.  Are you or.docxPlease answer the following questions.1.      1.  Are you or.docx
Please answer the following questions.1.      1.  Are you or.docx
ajoy21
 
Please answer the following question with 200-300 words.Q. Discu.docx
Please answer the following question with 200-300 words.Q. Discu.docxPlease answer the following question with 200-300 words.Q. Discu.docx
Please answer the following question with 200-300 words.Q. Discu.docx
ajoy21
 
Please answer the following question Why do you think the US ha.docx
Please answer the following question Why do you think the US ha.docxPlease answer the following question Why do you think the US ha.docx
Please answer the following question Why do you think the US ha.docx
ajoy21
 
Please answer the following questions. Define tunneling in the V.docx
Please answer the following questions. Define tunneling in the V.docxPlease answer the following questions. Define tunneling in the V.docx
Please answer the following questions. Define tunneling in the V.docx
ajoy21
 
Please answer the following questions1. How can you stimulate the.docx
Please answer the following questions1. How can you stimulate the.docxPlease answer the following questions1. How can you stimulate the.docx
Please answer the following questions1. How can you stimulate the.docx
ajoy21
 
Please answer the following questions very deeply and presicely .docx
Please answer the following questions very deeply and presicely .docxPlease answer the following questions very deeply and presicely .docx
Please answer the following questions very deeply and presicely .docx
ajoy21
 
Please answer the following questions in an informal 1 ½ - 2-page es.docx
Please answer the following questions in an informal 1 ½ - 2-page es.docxPlease answer the following questions in an informal 1 ½ - 2-page es.docx
Please answer the following questions in an informal 1 ½ - 2-page es.docx
ajoy21
 
Please answer the following questions in a response of 150 to 200 wo.docx
Please answer the following questions in a response of 150 to 200 wo.docxPlease answer the following questions in a response of 150 to 200 wo.docx
Please answer the following questions in a response of 150 to 200 wo.docx
ajoy21
 
Please answer these questions regarding the (TILA) Truth in Lending .docx
Please answer these questions regarding the (TILA) Truth in Lending .docxPlease answer these questions regarding the (TILA) Truth in Lending .docx
Please answer these questions regarding the (TILA) Truth in Lending .docx
ajoy21
 
Please answer the following question pertaining to psychology. Inc.docx
Please answer the following question pertaining to psychology. Inc.docxPlease answer the following question pertaining to psychology. Inc.docx
Please answer the following question pertaining to psychology. Inc.docx
ajoy21
 
Please answer the following questions in a response of 250 to 300 .docx
Please answer the following questions in a response of 250 to 300 .docxPlease answer the following questions in a response of 250 to 300 .docx
Please answer the following questions in a response of 250 to 300 .docx
ajoy21
 
Please answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docxPlease answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docx
ajoy21
 

More from ajoy21 (20)

Please complete the assignment listed below.Define and explain, us.docx
Please complete the assignment listed below.Define and explain, us.docxPlease complete the assignment listed below.Define and explain, us.docx
Please complete the assignment listed below.Define and explain, us.docx
 
Please cite sources for each question. Do not use the same sources f.docx
Please cite sources for each question. Do not use the same sources f.docxPlease cite sources for each question. Do not use the same sources f.docx
Please cite sources for each question. Do not use the same sources f.docx
 
Please choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docxPlease choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docx
 
Please check the attachment for my paper.Please add citations to a.docx
Please check the attachment for my paper.Please add citations to a.docxPlease check the attachment for my paper.Please add citations to a.docx
Please check the attachment for my paper.Please add citations to a.docx
 
Please answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docxPlease answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docx
 
Please attach Non-nursing theorist summaries.JigsawExecutive .docx
Please attach Non-nursing theorist summaries.JigsawExecutive .docxPlease attach Non-nursing theorist summaries.JigsawExecutive .docx
Please attach Non-nursing theorist summaries.JigsawExecutive .docx
 
Please answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docxPlease answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docx
 
Please answer the following questions. Please cite your references..docx
Please answer the following questions. Please cite your references..docxPlease answer the following questions. Please cite your references..docx
Please answer the following questions. Please cite your references..docx
 
Please answer the following questions.1.      1.  Are you or.docx
Please answer the following questions.1.      1.  Are you or.docxPlease answer the following questions.1.      1.  Are you or.docx
Please answer the following questions.1.      1.  Are you or.docx
 
Please answer the following question with 200-300 words.Q. Discu.docx
Please answer the following question with 200-300 words.Q. Discu.docxPlease answer the following question with 200-300 words.Q. Discu.docx
Please answer the following question with 200-300 words.Q. Discu.docx
 
Please answer the following question Why do you think the US ha.docx
Please answer the following question Why do you think the US ha.docxPlease answer the following question Why do you think the US ha.docx
Please answer the following question Why do you think the US ha.docx
 
Please answer the following questions. Define tunneling in the V.docx
Please answer the following questions. Define tunneling in the V.docxPlease answer the following questions. Define tunneling in the V.docx
Please answer the following questions. Define tunneling in the V.docx
 
Please answer the following questions1. How can you stimulate the.docx
Please answer the following questions1. How can you stimulate the.docxPlease answer the following questions1. How can you stimulate the.docx
Please answer the following questions1. How can you stimulate the.docx
 
Please answer the following questions very deeply and presicely .docx
Please answer the following questions very deeply and presicely .docxPlease answer the following questions very deeply and presicely .docx
Please answer the following questions very deeply and presicely .docx
 
Please answer the following questions in an informal 1 ½ - 2-page es.docx
Please answer the following questions in an informal 1 ½ - 2-page es.docxPlease answer the following questions in an informal 1 ½ - 2-page es.docx
Please answer the following questions in an informal 1 ½ - 2-page es.docx
 
Please answer the following questions in a response of 150 to 200 wo.docx
Please answer the following questions in a response of 150 to 200 wo.docxPlease answer the following questions in a response of 150 to 200 wo.docx
Please answer the following questions in a response of 150 to 200 wo.docx
 
Please answer these questions regarding the (TILA) Truth in Lending .docx
Please answer these questions regarding the (TILA) Truth in Lending .docxPlease answer these questions regarding the (TILA) Truth in Lending .docx
Please answer these questions regarding the (TILA) Truth in Lending .docx
 
Please answer the following question pertaining to psychology. Inc.docx
Please answer the following question pertaining to psychology. Inc.docxPlease answer the following question pertaining to psychology. Inc.docx
Please answer the following question pertaining to psychology. Inc.docx
 
Please answer the following questions in a response of 250 to 300 .docx
Please answer the following questions in a response of 250 to 300 .docxPlease answer the following questions in a response of 250 to 300 .docx
Please answer the following questions in a response of 250 to 300 .docx
 
Please answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docxPlease answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docx
 

Recently uploaded

How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 

Recently uploaded (20)

How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 

Complete the C++ program and implement the routines that are n.docx

  • 1. // Complete the C++ program and implement the routines that are not implemented #include <iostream> #include <iomanip> #include <fstream> #include <string> #include <vector> using namespace std; class TreeStruct; class Tree; class Stack; class Queue; typedef TreeStruct* TreeStructPtr; typedef Tree* TreePtr; class Stack { private: vector<TreeStructPtr> s; public: void push(TreeStructPtr ptr) {s.insert(s.begin(), ptr);} TreeStructPtr pop(){ TreeStructPtr ptr = s[0]; s.erase(s.begin()); return ptr;} bool empty(){return (s.size()==0);} }; class Queue { private: vector<TreeStructPtr> q; public: void push(TreeStructPtr ptr) {q.push_back(ptr);} TreeStructPtr pop(){ TreeStructPtr ptr = q[0]; q.erase(q.begin()); return ptr;} bool empty(){return (q.size()==0);} }; class TreeStruct { public: int Number; TreeStructPtr Left; TreeStructPtr Right; }; class Tree { public: TreeStructPtr TreeRoot; Tree(); void InsertIntoTree(TreeStructPtr& Root, int num); int FindMaxLen(TreeStructPtr Root); int FindMinLen(TreeStructPtr Root); int CountNodes(TreeStructPtr Root); void Copy(TreeStructPtr Root1, TreeStructPtr& Root2); //copies one tree into another bool Search(TreeStructPtr Root, int n); void PrintInOrderTree(TreeStructPtr Root); void PrintPreOrderTree(TreeStructPtr Root); void PrintPostOrderTree(TreeStructPtr Root); void PrintPreOrderTreeWithStack(TreeStructPtr Root); void PrintBreadthFirstWithQueue(TreeStructPtr Root); }; // ---------- ------------------------------------------------------ // tree constructor Tree::Tree() { TreeRoot = NULL; } //---------------- ------------------------------------------------ void Copy(TreeStructPtr Root1, TreeStructPtr& Root2) //copies one tree into another { } //---------------------------------------------- ------------------ // Inserting into the tree using recursion void Tree::InsertIntoTree(TreeStructPtr& Root, int x) { } //---------- ------------------------------------------------------ int
  • 2. Tree::FindMaxLen(TreeStructPtr Root) { return 0; } // ---- ------------------------------------------------------------ int Tree::FindMinLen(TreeStructPtr Root) { if (Root==NULL) return(0); else if (Root->Right==NULL) return(1+FindMinLen(Root->Left)); else if (Root- >Left==NULL) return(1+FindMinLen(Root->Right)); else { int CountLeft = 1 + FindMinLen(Root->Left); int CountRight = 1 + FindMinLen(Root->Right); if (CountLeft < CountRight) return(CountLeft); else return(CountRight); } } //------------------------- --------------------------------------- int Tree::CountNodes(TreeStructPtr Root) { return 0; } //----- ----------------------------------------------------------- bool Tree::Search(TreeStructPtr Root, int n) { return " "; } //- --------------------------------------------------------------- void Tree::PrintInOrderTree(TreeStructPtr Root) { } //----------------- ----------------------------------------------- void Tree::PrintPreOrderTree(TreeStructPtr Root) { } // ---------------- ------------------------------------------------ void Tree::PrintPostOrderTree(TreeStructPtr Root) { } //-------------- -------------------------------------------------- void Tree::PrintPreOrderTreeWithStack(TreeStructPtr Root) { Stack stk; TreeStructPtr p = Root; if (p != NULL) { stk.push(p); while (!stk.empty()) { p = stk.pop(); cout << p->Number << "-->"; if (p->Right != NULL) stk.push(p->Right); if (p->Left != NULL) stk.push(p->Left); } } } //------------------------------------------------------------ ---- void Tree::PrintBreadthFirstWithQueue(TreeStructPtr Root) { } //---------------------------------------------------------------- void main() { Tree t; t.InsertIntoTree(t.TreeRoot, 15); t.InsertIntoTree(t.TreeRoot, 20); t.InsertIntoTree(t.TreeRoot, 10); t.InsertIntoTree(t.TreeRoot, 8); t.InsertIntoTree(t.TreeRoot, 9); t.InsertIntoTree(t.TreeRoot, 17); t.InsertIntoTree(t.TreeRoot, 21);
  • 3. t.InsertIntoTree(t.TreeRoot, 22); t.InsertIntoTree(t.TreeRoot, 23); t.InsertIntoTree(t.TreeRoot, 24); t.InsertIntoTree(t.TreeRoot, 25); t.InsertIntoTree(t.TreeRoot, 26); t.InsertIntoTree(t.TreeRoot, 11); cout << " Printing Pre Order " << endl; t.PrintPreOrderTree(t.TreeRoot); cout << " -----------------------------------------------" << endl; getchar(); cout << "Printing Post Order " << endl; t.PrintPostOrderTree(t.TreeRoot); cout << " -------------------- ---------------------------" << endl; getchar(); cout << "Printing In Order " << endl; t.PrintInOrderTree(t.TreeRoot); cout << " -----------------------------------------------" << endl; getchar(); cout << boolalpha << endl << endl; cout << " Searching 30: " << t.Search(t.TreeRoot, 30) << endl; cout << " Searching 8: " << t.Search(t.TreeRoot, 8) << endl; cout << " Searching 10: " << t.Search(t.TreeRoot, 10) << endl; cout << "-------------------------------------------" << endl; getchar(); cout << "Printing Pre Order with Stack " << endl; t.PrintPreOrderTreeWithStack(t.TreeRoot); cout << " --------- --------------------------------------" << endl; getchar(); cout << "Printing level by level BreathFirst Traversal " << endl; t.PrintBreadthFirstWithQueue(t.TreeRoot); cout << " ---------- -------------------------------------" << endl; getchar(); cout << endl; int MaxLen = t.FindMaxLen(t.TreeRoot); int MinLen = t.FindMinLen(t.TreeRoot); int TotalNodes = t.CountNodes(t.TreeRoot); cout << "Max is " << MaxLen << endl; cout << "Min is " << MinLen << endl; cout << "Num of Nodes is " << TotalNodes << endl; cout << "----------------- ------------------------------" << endl; getchar(); Tree t2; Copy(t.TreeRoot, t2.TreeRoot); cout << "Printing In Order the copy of the tree" << endl; t2.PrintInOrderTree(t2.TreeRoot); cout << " -----------------------------------------------" << endl; } //---------------------------------------------------------------- /* Your output should look like the foolowing Printing Pre Order 15-->10-->8-->9-->11-->20-->17-->21-->22-->23-->24-->25-- >26--> ----------------------------------------------- Printing Post Order 9-->8-->11-->10-->17-->26-->25-->24-->23-->22-->21--
  • 4. >20-->15--> ----------------------------------------------- Printing In Order 8-->9-->10-->11-->15-->17-->20-->21-->22-->23-- >24-->25-->26--> ----------------------------------------------- Searching 30: false Searching 8: true Searching 10: true ------- ------------------------------------ Printing Pre Order with Stack 15-->10-->8-->9-->11-->20-->17-->21-->22-->23-->24-->25-- >26--> ----------------------------------------------- Printing level by level BreathFirst Traversal 15-->10-->20-->8-->11-->17-- >21-->9-->22-->23-->24-->25-->26--> ----------------------------- ------------------ Max is 8 Min is 3 Num of Nodes is 13 --------- -------------------------------------- Printing In Order the copy of the tree 8-->9-->10-->11-->15-->17-->20-->21-->22-->23-->24- ->25-->26--> ----------------------------------------------- Press any key to continue */ Solution Implemented the following 4 functions void Tree::InsertIntoTree(TreeStructPtr& Root, int x) { if (Root == NULL) { TreeStructPtr node = new TreeStruct(); node->Number = x; node->Left = NULL; node->Right = NULL; Root = node; } else {
  • 5. if (x <= Root->Number) { if (Root->Left != NULL) InsertIntoTree(Root->Left, x); else { TreeStructPtr node = new TreeStruct(); node->Number = x; node->Left = NULL; node->Right = NULL; Root->Left = node; } } else { if (Root->Right != NULL) InsertIntoTree(Root->Right, x); else { TreeStructPtr node = new TreeStruct(); node->Number = x; node->Left = NULL; node->Right = NULL; Root->Right = node; } } } } //---------------------------------------------------------------- void Tree::PrintInOrderTree(TreeStructPtr Root) {
  • 6. if (Root != NULL) { PrintInOrderTree(Root->Left); cout << Root->Number << "->"; PrintInOrderTree(Root->Right); } } //---------------------------------------------------------------- void Tree::PrintPreOrderTree(TreeStructPtr Root) { if (Root != NULL) { cout << Root->Number << "->"; PrintPreOrderTree(Root->Left); PrintPreOrderTree(Root->Right); } } //---------------------------------------------------------------- void Tree::PrintPostOrderTree(TreeStructPtr Root) { if (Root != NULL) { PrintPostOrderTree(Root->Left); PrintPostOrderTree(Root->Right); cout << Root->Number << "->"; } } --output with your main code for these 4 methods---------------
  • 7. Printing Pre Order 15->10->8->9->11->20->17->21->22->23->24->25->26-> Printing Post Order 9->8->11->10->17->26->25->24->23->22->21->20->15-> Printing In Order 8->9->10->11->15->17->20->21->22->23->24->25->26->