SlideShare a Scribd company logo
1 of 19
/ 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.be gin(),
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 { implement this } //---------------------------
------------------------------------- // Inserting into the tree using
recursion void Tree::InsertIntoTree(TreeStructPtr& Root, int x)
{ implement this } //------------------------------------------------
---------------- int Tree::FindMaxLen(TreeStructPtr Root) {
implement this } //----------------------------------------------------
------------ 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) { implement this
} //---------------------------------------------------------------- bool
Tree::Search(TreeStructPtr Root, int n) { implement this
} //---------------------------------------------------------------- void
Tree::PrintInOrderTree(TreeStructPtr Root) { implement this }
//---------------------------------------------------------------- void
Tree::PrintPreOrderTree(TreeStructPtr Root) { implement this
} //---------------------------------------------------------------- void
Tree::PrintPostOrderTree(TreeStructPtr Root) { implement this
} //---------------------------------------------------------------- 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)
{ implement this } //-------------------------------------------------
--------------- 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
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <vector>
#include <stdio.h>
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
{
if (Root1 == NULL) //base case to end recursion when at tree
end
Root2 == NULL;
else{
Root2->Number = Root1->Number;
// Just call recursively to copy the subtrees:
Copy(Root1->Left, Root2->Left);
Copy(Root1->Right, Root2->Right);
}
}
//----------------------------------------------------------------
// Inserting into the tree using recursion
void Tree::InsertIntoTree(TreeStructPtr& Root, int x)
{
TreeStructPtr p = Root, prev=Root;
while (p != NULL)
{ prev = p;
if (x < p->Number)
p = p->Left;
else if (x > p->Number)
p = p->Right;
else
{ cout << " !!!! " << x << " is already in the tree " << endl;
return;
}
}
TreeStructPtr NewNode;
NewNode = new (TreeStruct);
NewNode->Number = x;
NewNode->Left = NULL;
NewNode->Right = NULL;
if (Root == NULL)
Root = NewNode;
else if (prev->Number < x)
prev->Right = NewNode;
else
prev->Left = NewNode;
return;
}
//----------------------------------------------------------------
int Tree::FindMaxLen(TreeStructPtr Root)
{
if (Root == NULL)
return(0);
else if (Root->Right == NULL)
return(1+FindMaxLen(Root->Left));
else if (Root->Left == NULL)
return(1+FindMaxLen(Root->Right));
else
{
int CountLeft = 1 + FindMaxLen(Root->Left);
int CountRight = 1 + FindMaxLen(Root->Right);
if (CountLeft > CountRight)
return(CountLeft);
else
return(CountRight);
}
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)
{
if(Root == NULL) { //This node doesn't exist. Therefore there
are no nodes in this 'subtree'
return 0;
} else { //Add the size of the left and right trees, then add 1
(which is the current node)
return CountNodes(Root->Left) + CountNodes(Root->Right) +
1;
}
}
//----------------------------------------------------------------
bool Tree::Search(TreeStructPtr Root, int n)
{
bool found;
TreeStructPtr curr;
curr = Root;
found = false;
while ((curr != NULL) && (! found))
if (curr->Number == n)
found = true;
else if (n < curr->Number)
curr = curr->Left;
else
curr = curr->Right;
return found;
}
//----------------------------------------------------------------
void Tree::PrintInOrderTree(TreeStructPtr Root)
{
if (Root == NULL)return;
/* first recur on Left child */
PrintInOrderTree(Root->Left);
/* then print the data of node */
printf("%d-->", Root->Number);
/* now recur on Right child */
PrintInOrderTree(Root->Right);
}
//----------------------------------------------------------------
void Tree::PrintPreOrderTree(TreeStructPtr Root)
{
if (Root == NULL)
return;
/* first print data of node */
printf("%d-->", Root->Number);
/* then recur on Left sutree */
PrintPreOrderTree(Root->Left);
/* now recur on Right subtree */
PrintPreOrderTree(Root->Right);
}
//----------------------------------------------------------------
void Tree::PrintPostOrderTree(TreeStructPtr Root)
{
if (Root == NULL)
return;
// first recur on Left subtree
PrintPostOrderTree(Root->Left);
// then recur on Right subtree
PrintPostOrderTree(Root->Right);
// now deal with the node
printf("%d-->", Root->Number);
}
//----------------------------------------------------------------
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)
{
Queue que;
TreeStructPtr p = Root;
if (p != NULL)
{
que.push(p);
while (!que.empty())
{
p = que.pop();
cout << p->Number << "-->";
if (p ->Left != NULL)
que.push(p->Left);
if (p->Right != NULL)
que.push(p->Right);
}
}
}
//----------------------------------------------------------------
int 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;
cout << "Printing Post Order " << endl;
t.PrintPostOrderTree(t.TreeRoot);
cout << " -----------------------------------------------" << endl;
cout << "Printing In Order " << endl;
t.PrintInOrderTree(t.TreeRoot);
cout << " -----------------------------------------------" << endl;
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;
cout << "Printing Pre Order with Stack " << endl;
t.PrintPreOrderTreeWithStack(t.TreeRoot);
cout << " -----------------------------------------------" << endl;
cout << "Printing level by level BreathFirst Traversal " <<
endl;
t.PrintBreadthFirstWithQueue(t.TreeRoot);
cout << " -----------------------------------------------" << endl;
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;
/*
Tree t2;
Copy(t.TreeRoot, t2.TreeRoot);
cout << "Printing In Order the copy of the tree" << endl;
t2.PrintInOrderTree(t2.TreeRoot);
cout << " -----------------------------------------------" << endl;
*/
return 0;
}
//----------------------------------------------------------------
/* 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
*/

More Related Content

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

Complete the C++ program and implement the routines that are n.docx
    Complete the C++ program and implement the routines that are n.docx    Complete the C++ program and implement the routines that are n.docx
Complete the C++ program and implement the routines that are n.docxShiraPrater50
 
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.pdfmichardsonkhaicarr37
 
C++ extension methods
C++ extension methodsC++ extension methods
C++ extension methodsphil_nash
 
Data StructuresPlease I need help completing this c++ program..pdf
Data StructuresPlease I need help completing this c++ program..pdfData StructuresPlease I need help completing this c++ program..pdf
Data StructuresPlease I need help completing this c++ program..pdfarkleatheray
 
Create a class BinarySearchTree- A class that implements the ADT binar.pdf
Create a class BinarySearchTree- A class that implements the ADT binar.pdfCreate a class BinarySearchTree- A class that implements the ADT binar.pdf
Create a class BinarySearchTree- A class that implements the ADT binar.pdfshyamsunder1211
 
I want help in the following C++ programming task. Please do coding .pdf
I want help in the following C++ programming task. Please do coding .pdfI want help in the following C++ programming task. Please do coding .pdf
I want help in the following C++ programming task. Please do coding .pdfbermanbeancolungak45
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloadingkinan keshkeh
 
This is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdfThis is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdfkostikjaylonshaewe47
 
ANSimport java.util.Scanner; class Bina_node { Bina_node .pdf
ANSimport java.util.Scanner; class Bina_node { Bina_node .pdfANSimport java.util.Scanner; class Bina_node { Bina_node .pdf
ANSimport java.util.Scanner; class Bina_node { Bina_node .pdfanukoolelectronics
 
.NET 2015: Будущее рядом
.NET 2015: Будущее рядом.NET 2015: Будущее рядом
.NET 2015: Будущее рядомAndrey Akinshin
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYMalikireddy Bramhananda Reddy
 
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docxAvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docxrock73
 
C++ adt c++ implementations
C++   adt c++ implementationsC++   adt c++ implementations
C++ adt c++ implementationsRex Mwamba
 
include ltfunctionalgt include ltiteratorgt inclu.pdf
include ltfunctionalgt include ltiteratorgt inclu.pdfinclude ltfunctionalgt include ltiteratorgt inclu.pdf
include ltfunctionalgt include ltiteratorgt inclu.pdfnaslin841216
 
Please teach me how to fix the errors and where should be modified. .pdf
Please teach me how to fix the errors and where should be modified. .pdfPlease teach me how to fix the errors and where should be modified. .pdf
Please teach me how to fix the errors and where should be modified. .pdfamarndsons
 
1. Add a breadth-first (level-order) traversal function to the binar.pdf
1. Add a breadth-first (level-order) traversal function to the binar.pdf1. Add a breadth-first (level-order) traversal function to the binar.pdf
1. Add a breadth-first (level-order) traversal function to the binar.pdfarjuncp10
 
GIVEN CODE template -typename T- class DList { private- struct Node {.docx
GIVEN CODE template -typename T- class DList { private- struct Node {.docxGIVEN CODE template -typename T- class DList { private- struct Node {.docx
GIVEN CODE template -typename T- class DList { private- struct Node {.docxLeonardN9WWelchw
 

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

Complete the C++ program and implement the routines that are n.docx
    Complete the C++ program and implement the routines that are n.docx    Complete the C++ program and implement the routines that are n.docx
Complete the C++ program and implement the routines that are n.docx
 
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
 
C++ extension methods
C++ extension methodsC++ extension methods
C++ extension methods
 
Data StructuresPlease I need help completing this c++ program..pdf
Data StructuresPlease I need help completing this c++ program..pdfData StructuresPlease I need help completing this c++ program..pdf
Data StructuresPlease I need help completing this c++ program..pdf
 
Create a class BinarySearchTree- A class that implements the ADT binar.pdf
Create a class BinarySearchTree- A class that implements the ADT binar.pdfCreate a class BinarySearchTree- A class that implements the ADT binar.pdf
Create a class BinarySearchTree- A class that implements the ADT binar.pdf
 
I want help in the following C++ programming task. Please do coding .pdf
I want help in the following C++ programming task. Please do coding .pdfI want help in the following C++ programming task. Please do coding .pdf
I want help in the following C++ programming task. Please do coding .pdf
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
 
DS Code (CWH).docx
DS Code (CWH).docxDS Code (CWH).docx
DS Code (CWH).docx
 
This is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdfThis is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdf
 
ANSimport java.util.Scanner; class Bina_node { Bina_node .pdf
ANSimport java.util.Scanner; class Bina_node { Bina_node .pdfANSimport java.util.Scanner; class Bina_node { Bina_node .pdf
ANSimport java.util.Scanner; class Bina_node { Bina_node .pdf
 
.NET 2015: Будущее рядом
.NET 2015: Будущее рядом.NET 2015: Будущее рядом
.NET 2015: Будущее рядом
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
 
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docxAvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
 
The STL
The STLThe STL
The STL
 
C++ adt c++ implementations
C++   adt c++ implementationsC++   adt c++ implementations
C++ adt c++ implementations
 
include ltfunctionalgt include ltiteratorgt inclu.pdf
include ltfunctionalgt include ltiteratorgt inclu.pdfinclude ltfunctionalgt include ltiteratorgt inclu.pdf
include ltfunctionalgt include ltiteratorgt inclu.pdf
 
Please teach me how to fix the errors and where should be modified. .pdf
Please teach me how to fix the errors and where should be modified. .pdfPlease teach me how to fix the errors and where should be modified. .pdf
Please teach me how to fix the errors and where should be modified. .pdf
 
Opp compile
Opp compileOpp compile
Opp compile
 
1. Add a breadth-first (level-order) traversal function to the binar.pdf
1. Add a breadth-first (level-order) traversal function to the binar.pdf1. Add a breadth-first (level-order) traversal function to the binar.pdf
1. Add a breadth-first (level-order) traversal function to the binar.pdf
 
GIVEN CODE template -typename T- class DList { private- struct Node {.docx
GIVEN CODE template -typename T- class DList { private- struct Node {.docxGIVEN CODE template -typename T- class DList { private- struct Node {.docx
GIVEN CODE template -typename T- class DList { private- struct Node {.docx
 

More from ShiraPrater50

Read Chapter 3. Answer the following questions1.Wha.docx
Read Chapter 3. Answer the following questions1.Wha.docxRead Chapter 3. Answer the following questions1.Wha.docx
Read Chapter 3. Answer the following questions1.Wha.docxShiraPrater50
 
Read Chapter 15 and answer the following questions 1.  De.docx
Read Chapter 15 and answer the following questions 1.  De.docxRead Chapter 15 and answer the following questions 1.  De.docx
Read Chapter 15 and answer the following questions 1.  De.docxShiraPrater50
 
Read Chapter 2 and answer the following questions1.  List .docx
Read Chapter 2 and answer the following questions1.  List .docxRead Chapter 2 and answer the following questions1.  List .docx
Read Chapter 2 and answer the following questions1.  List .docxShiraPrater50
 
Read chapter 7 and write the book report  The paper should be .docx
Read chapter 7 and write the book report  The paper should be .docxRead chapter 7 and write the book report  The paper should be .docx
Read chapter 7 and write the book report  The paper should be .docxShiraPrater50
 
Read Chapter 7 and answer the following questions1.  What a.docx
Read Chapter 7 and answer the following questions1.  What a.docxRead Chapter 7 and answer the following questions1.  What a.docx
Read Chapter 7 and answer the following questions1.  What a.docxShiraPrater50
 
Read chapter 14, 15 and 18 of the class textbook.Saucier.docx
Read chapter 14, 15 and 18 of the class textbook.Saucier.docxRead chapter 14, 15 and 18 of the class textbook.Saucier.docx
Read chapter 14, 15 and 18 of the class textbook.Saucier.docxShiraPrater50
 
Read Chapter 10 APA FORMAT1. In the last century, what historica.docx
Read Chapter 10 APA FORMAT1. In the last century, what historica.docxRead Chapter 10 APA FORMAT1. In the last century, what historica.docx
Read Chapter 10 APA FORMAT1. In the last century, what historica.docxShiraPrater50
 
Read chapter 7 and write the book report  The paper should b.docx
Read chapter 7 and write the book report  The paper should b.docxRead chapter 7 and write the book report  The paper should b.docx
Read chapter 7 and write the book report  The paper should b.docxShiraPrater50
 
Read Chapter 14 and answer the following questions1.  Explain t.docx
Read Chapter 14 and answer the following questions1.  Explain t.docxRead Chapter 14 and answer the following questions1.  Explain t.docx
Read Chapter 14 and answer the following questions1.  Explain t.docxShiraPrater50
 
Read Chapter 2 first. Then come to this assignment.The first t.docx
Read Chapter 2 first. Then come to this assignment.The first t.docxRead Chapter 2 first. Then come to this assignment.The first t.docx
Read Chapter 2 first. Then come to this assignment.The first t.docxShiraPrater50
 
Journal of Public Affairs Education 515Teaching Grammar a.docx
 Journal of Public Affairs Education 515Teaching Grammar a.docx Journal of Public Affairs Education 515Teaching Grammar a.docx
Journal of Public Affairs Education 515Teaching Grammar a.docxShiraPrater50
 
Learner Guide TLIR5014 Manage suppliers TLIR.docx
 Learner Guide TLIR5014 Manage suppliers TLIR.docx Learner Guide TLIR5014 Manage suppliers TLIR.docx
Learner Guide TLIR5014 Manage suppliers TLIR.docxShiraPrater50
 
Lab 5 Nessus Vulnerability Scan Report © 2012 by Jone.docx
 Lab 5 Nessus Vulnerability Scan Report © 2012 by Jone.docx Lab 5 Nessus Vulnerability Scan Report © 2012 by Jone.docx
Lab 5 Nessus Vulnerability Scan Report © 2012 by Jone.docxShiraPrater50
 
Leveled and Exclusionary Tracking English Learners Acce.docx
 Leveled and Exclusionary Tracking English Learners Acce.docx Leveled and Exclusionary Tracking English Learners Acce.docx
Leveled and Exclusionary Tracking English Learners Acce.docxShiraPrater50
 
Lab 5 Nessus Vulnerability Scan Report © 2015 by Jone.docx
 Lab 5 Nessus Vulnerability Scan Report © 2015 by Jone.docx Lab 5 Nessus Vulnerability Scan Report © 2015 by Jone.docx
Lab 5 Nessus Vulnerability Scan Report © 2015 by Jone.docxShiraPrater50
 
MBA 6941, Managing Project Teams 1 Course Learning Ou.docx
 MBA 6941, Managing Project Teams 1 Course Learning Ou.docx MBA 6941, Managing Project Teams 1 Course Learning Ou.docx
MBA 6941, Managing Project Teams 1 Course Learning Ou.docxShiraPrater50
 
Inventory Decisions in Dells Supply ChainAuthor(s) Ro.docx
 Inventory Decisions in Dells Supply ChainAuthor(s) Ro.docx Inventory Decisions in Dells Supply ChainAuthor(s) Ro.docx
Inventory Decisions in Dells Supply ChainAuthor(s) Ro.docxShiraPrater50
 
It’s Your Choice 10 – Clear Values 2nd Chain Link- Trade-offs .docx
 It’s Your Choice 10 – Clear Values 2nd Chain Link- Trade-offs .docx It’s Your Choice 10 – Clear Values 2nd Chain Link- Trade-offs .docx
It’s Your Choice 10 – Clear Values 2nd Chain Link- Trade-offs .docxShiraPrater50
 
MBA 5101, Strategic Management and Business Policy 1 .docx
 MBA 5101, Strategic Management and Business Policy 1 .docx MBA 5101, Strategic Management and Business Policy 1 .docx
MBA 5101, Strategic Management and Business Policy 1 .docxShiraPrater50
 
MAJOR WORLD RELIGIONSJudaismJudaism (began .docx
 MAJOR WORLD RELIGIONSJudaismJudaism (began .docx MAJOR WORLD RELIGIONSJudaismJudaism (began .docx
MAJOR WORLD RELIGIONSJudaismJudaism (began .docxShiraPrater50
 

More from ShiraPrater50 (20)

Read Chapter 3. Answer the following questions1.Wha.docx
Read Chapter 3. Answer the following questions1.Wha.docxRead Chapter 3. Answer the following questions1.Wha.docx
Read Chapter 3. Answer the following questions1.Wha.docx
 
Read Chapter 15 and answer the following questions 1.  De.docx
Read Chapter 15 and answer the following questions 1.  De.docxRead Chapter 15 and answer the following questions 1.  De.docx
Read Chapter 15 and answer the following questions 1.  De.docx
 
Read Chapter 2 and answer the following questions1.  List .docx
Read Chapter 2 and answer the following questions1.  List .docxRead Chapter 2 and answer the following questions1.  List .docx
Read Chapter 2 and answer the following questions1.  List .docx
 
Read chapter 7 and write the book report  The paper should be .docx
Read chapter 7 and write the book report  The paper should be .docxRead chapter 7 and write the book report  The paper should be .docx
Read chapter 7 and write the book report  The paper should be .docx
 
Read Chapter 7 and answer the following questions1.  What a.docx
Read Chapter 7 and answer the following questions1.  What a.docxRead Chapter 7 and answer the following questions1.  What a.docx
Read Chapter 7 and answer the following questions1.  What a.docx
 
Read chapter 14, 15 and 18 of the class textbook.Saucier.docx
Read chapter 14, 15 and 18 of the class textbook.Saucier.docxRead chapter 14, 15 and 18 of the class textbook.Saucier.docx
Read chapter 14, 15 and 18 of the class textbook.Saucier.docx
 
Read Chapter 10 APA FORMAT1. In the last century, what historica.docx
Read Chapter 10 APA FORMAT1. In the last century, what historica.docxRead Chapter 10 APA FORMAT1. In the last century, what historica.docx
Read Chapter 10 APA FORMAT1. In the last century, what historica.docx
 
Read chapter 7 and write the book report  The paper should b.docx
Read chapter 7 and write the book report  The paper should b.docxRead chapter 7 and write the book report  The paper should b.docx
Read chapter 7 and write the book report  The paper should b.docx
 
Read Chapter 14 and answer the following questions1.  Explain t.docx
Read Chapter 14 and answer the following questions1.  Explain t.docxRead Chapter 14 and answer the following questions1.  Explain t.docx
Read Chapter 14 and answer the following questions1.  Explain t.docx
 
Read Chapter 2 first. Then come to this assignment.The first t.docx
Read Chapter 2 first. Then come to this assignment.The first t.docxRead Chapter 2 first. Then come to this assignment.The first t.docx
Read Chapter 2 first. Then come to this assignment.The first t.docx
 
Journal of Public Affairs Education 515Teaching Grammar a.docx
 Journal of Public Affairs Education 515Teaching Grammar a.docx Journal of Public Affairs Education 515Teaching Grammar a.docx
Journal of Public Affairs Education 515Teaching Grammar a.docx
 
Learner Guide TLIR5014 Manage suppliers TLIR.docx
 Learner Guide TLIR5014 Manage suppliers TLIR.docx Learner Guide TLIR5014 Manage suppliers TLIR.docx
Learner Guide TLIR5014 Manage suppliers TLIR.docx
 
Lab 5 Nessus Vulnerability Scan Report © 2012 by Jone.docx
 Lab 5 Nessus Vulnerability Scan Report © 2012 by Jone.docx Lab 5 Nessus Vulnerability Scan Report © 2012 by Jone.docx
Lab 5 Nessus Vulnerability Scan Report © 2012 by Jone.docx
 
Leveled and Exclusionary Tracking English Learners Acce.docx
 Leveled and Exclusionary Tracking English Learners Acce.docx Leveled and Exclusionary Tracking English Learners Acce.docx
Leveled and Exclusionary Tracking English Learners Acce.docx
 
Lab 5 Nessus Vulnerability Scan Report © 2015 by Jone.docx
 Lab 5 Nessus Vulnerability Scan Report © 2015 by Jone.docx Lab 5 Nessus Vulnerability Scan Report © 2015 by Jone.docx
Lab 5 Nessus Vulnerability Scan Report © 2015 by Jone.docx
 
MBA 6941, Managing Project Teams 1 Course Learning Ou.docx
 MBA 6941, Managing Project Teams 1 Course Learning Ou.docx MBA 6941, Managing Project Teams 1 Course Learning Ou.docx
MBA 6941, Managing Project Teams 1 Course Learning Ou.docx
 
Inventory Decisions in Dells Supply ChainAuthor(s) Ro.docx
 Inventory Decisions in Dells Supply ChainAuthor(s) Ro.docx Inventory Decisions in Dells Supply ChainAuthor(s) Ro.docx
Inventory Decisions in Dells Supply ChainAuthor(s) Ro.docx
 
It’s Your Choice 10 – Clear Values 2nd Chain Link- Trade-offs .docx
 It’s Your Choice 10 – Clear Values 2nd Chain Link- Trade-offs .docx It’s Your Choice 10 – Clear Values 2nd Chain Link- Trade-offs .docx
It’s Your Choice 10 – Clear Values 2nd Chain Link- Trade-offs .docx
 
MBA 5101, Strategic Management and Business Policy 1 .docx
 MBA 5101, Strategic Management and Business Policy 1 .docx MBA 5101, Strategic Management and Business Policy 1 .docx
MBA 5101, Strategic Management and Business Policy 1 .docx
 
MAJOR WORLD RELIGIONSJudaismJudaism (began .docx
 MAJOR WORLD RELIGIONSJudaismJudaism (began .docx MAJOR WORLD RELIGIONSJudaismJudaism (began .docx
MAJOR WORLD RELIGIONSJudaismJudaism (began .docx
 

Recently uploaded

PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...KokoStevan
 

Recently uploaded (20)

PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 

Complete the C++ program and implement the routines that are not .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.be gin(), 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 { implement this } //--------------------------- ------------------------------------- // Inserting into the tree using recursion void Tree::InsertIntoTree(TreeStructPtr& Root, int x) { implement this } //------------------------------------------------
  • 2. ---------------- int Tree::FindMaxLen(TreeStructPtr Root) { implement this } //---------------------------------------------------- ------------ 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) { implement this } //---------------------------------------------------------------- bool Tree::Search(TreeStructPtr Root, int n) { implement this } //---------------------------------------------------------------- void Tree::PrintInOrderTree(TreeStructPtr Root) { implement this } //---------------------------------------------------------------- void Tree::PrintPreOrderTree(TreeStructPtr Root) { implement this } //---------------------------------------------------------------- void Tree::PrintPostOrderTree(TreeStructPtr Root) { implement this } //---------------------------------------------------------------- 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) { implement this } //------------------------------------------------- --------------- 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,
  • 3. 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
  • 4. 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 #include <iostream> #include <iomanip> #include <fstream> #include <string> #include <vector> #include <stdio.h> using namespace std; class TreeStruct;
  • 5. 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);}
  • 6. }; 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);
  • 7. 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 { if (Root1 == NULL) //base case to end recursion when at tree end Root2 == NULL; else{ Root2->Number = Root1->Number; // Just call recursively to copy the subtrees: Copy(Root1->Left, Root2->Left); Copy(Root1->Right, Root2->Right); } } //----------------------------------------------------------------
  • 8. // Inserting into the tree using recursion void Tree::InsertIntoTree(TreeStructPtr& Root, int x) { TreeStructPtr p = Root, prev=Root; while (p != NULL) { prev = p; if (x < p->Number) p = p->Left; else if (x > p->Number) p = p->Right; else { cout << " !!!! " << x << " is already in the tree " << endl; return; } } TreeStructPtr NewNode; NewNode = new (TreeStruct); NewNode->Number = x; NewNode->Left = NULL; NewNode->Right = NULL; if (Root == NULL) Root = NewNode; else if (prev->Number < x) prev->Right = NewNode; else
  • 9. prev->Left = NewNode; return; } //---------------------------------------------------------------- int Tree::FindMaxLen(TreeStructPtr Root) { if (Root == NULL) return(0); else if (Root->Right == NULL) return(1+FindMaxLen(Root->Left)); else if (Root->Left == NULL) return(1+FindMaxLen(Root->Right)); else { int CountLeft = 1 + FindMaxLen(Root->Left); int CountRight = 1 + FindMaxLen(Root->Right); if (CountLeft > CountRight) return(CountLeft); else return(CountRight); } return 0; } //----------------------------------------------------------------
  • 10. 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) { if(Root == NULL) { //This node doesn't exist. Therefore there are no nodes in this 'subtree' return 0;
  • 11. } else { //Add the size of the left and right trees, then add 1 (which is the current node) return CountNodes(Root->Left) + CountNodes(Root->Right) + 1; } } //---------------------------------------------------------------- bool Tree::Search(TreeStructPtr Root, int n) { bool found; TreeStructPtr curr; curr = Root; found = false; while ((curr != NULL) && (! found)) if (curr->Number == n) found = true; else if (n < curr->Number) curr = curr->Left; else curr = curr->Right; return found; } //----------------------------------------------------------------
  • 12. void Tree::PrintInOrderTree(TreeStructPtr Root) { if (Root == NULL)return; /* first recur on Left child */ PrintInOrderTree(Root->Left); /* then print the data of node */ printf("%d-->", Root->Number); /* now recur on Right child */ PrintInOrderTree(Root->Right); } //---------------------------------------------------------------- void Tree::PrintPreOrderTree(TreeStructPtr Root) { if (Root == NULL) return; /* first print data of node */ printf("%d-->", Root->Number); /* then recur on Left sutree */ PrintPreOrderTree(Root->Left);
  • 13. /* now recur on Right subtree */ PrintPreOrderTree(Root->Right); } //---------------------------------------------------------------- void Tree::PrintPostOrderTree(TreeStructPtr Root) { if (Root == NULL) return; // first recur on Left subtree PrintPostOrderTree(Root->Left); // then recur on Right subtree PrintPostOrderTree(Root->Right); // now deal with the node printf("%d-->", Root->Number); } //---------------------------------------------------------------- void Tree::PrintPreOrderTreeWithStack(TreeStructPtr Root) { Stack stk; TreeStructPtr p = Root; if (p != NULL) {
  • 14. 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) { Queue que; TreeStructPtr p = Root; if (p != NULL) { que.push(p); while (!que.empty()) { p = que.pop(); cout << p->Number << "-->"; if (p ->Left != NULL)
  • 15. que.push(p->Left); if (p->Right != NULL) que.push(p->Right); } } } //---------------------------------------------------------------- int 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);
  • 16. cout << " -----------------------------------------------" << endl; cout << "Printing Post Order " << endl; t.PrintPostOrderTree(t.TreeRoot); cout << " -----------------------------------------------" << endl; cout << "Printing In Order " << endl; t.PrintInOrderTree(t.TreeRoot); cout << " -----------------------------------------------" << endl; 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; cout << "Printing Pre Order with Stack " << endl; t.PrintPreOrderTreeWithStack(t.TreeRoot); cout << " -----------------------------------------------" << endl; cout << "Printing level by level BreathFirst Traversal " << endl; t.PrintBreadthFirstWithQueue(t.TreeRoot);
  • 17. cout << " -----------------------------------------------" << endl; 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; /* Tree t2; Copy(t.TreeRoot, t2.TreeRoot); cout << "Printing In Order the copy of the tree" << endl; t2.PrintInOrderTree(t2.TreeRoot); cout << " -----------------------------------------------" << endl; */ return 0; } //---------------------------------------------------------------- /* Your output should look like the foolowing Printing Pre Order
  • 18. 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--> -----------------------------------------------
  • 19. 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 */