SlideShare a Scribd company logo
1 of 4
Download to read offline
"Templated Binary Tree" implementing function help ?
I need to implement header file which i am working on.
Void expandExternal and void preorder part :
1. Header File :
#ifndef BINARYTREE_H
#define BINARYTREE_H
#include
////////////////////////////////////
// Templated Node Interface
///////////////////////////////////
template // base element type
class Node { // a node of the tree
public:
Node() : elt(), par(NULL), left(NULL), right(NULL) { } // constructor
private:
E elt; // element value
Node* par; // parent
Node* left; // left child
Node* right; // right child
template friend class BinaryTree;
template friend class Position;
};
////////////////////////////////////
// Templated Binary Tree Interface
///////////////////////////////////
template // base element type
class BinaryTree
{
public: // public types
//Defines a node position
class Position
{
public:
Position(Node * _v = NULL) : v(_v) { } // constructor
//Returns the element at the position
E& operator*()
{
return v->elt;
}
//Returns a Position object
Position left() const // get left child
{
return Position(v->left);
}
//Returns a Position object
Position right() const // get right child
{
return Position(v->right);
}
//Returns a Position object
Position parent() const // get parent
{
return Position(v->par);
}
//Returns true or false
bool isRoot() const // root of tree?
{
return v->par == NULL;
}
//Returns true or false
bool isExternal() const // an external node?
{
return v->left == NULL && v->right == NULL;
}
//Returns true or false
bool isInternal() const // an external node?
{
return ! isExternal();
}
private:
Node* v;
template friend class BinaryTree;
};//End Position class definition
/* Position List type definition*/
typedef std::list PositionList;
public: //Binary member functions
BinaryTree() : _root(NULL), n(0) { }
~BinaryTree(); // The destructor need to properly deletes all nodes in the tree to prevent
memory leaks.
int size() const; // Returns and integer tof the number of nodes.
bool empty() const; // Returns a true if the tree is empty else false.
Position root() const; // Return the position of the root node.
void addRoot(); // Creates and adds the initial root node to the tree this must be added first.
void expandExternal(const Position& p); //Expands each external node with a left and right
child that are empty.
// What goes here?
PositionList positions() const; // Returns a std:list of the nodes in the tree call preorder()
function.
void preorder(Node* v, PositionList& pl) const; // Traversal algorithm for the tree to populate
the PositionList
// What goes here?
private:
Node * _root; // pointer to the root
int n; // number of nodes
};
#endif
Thank you
Solution
for the main function, try writing the code like this :
struct Node{
Comparable element;
Node *left;
Node *right;
Node(const Comparable & theElement, Node *lt, Node *rt )
: element( theElement ), left( lt ), right( rt ) {}
}; // Node{}
Node *root;
Node * findMin( Node *t ) const;
Node * findMax( Node *t ) const;

More Related Content

Similar to Templated Binary Tree implementing function help I need to im.pdf

C++ BinaryTree Help Creating main function for Trees...Here are .pdf
C++ BinaryTree Help  Creating main function for Trees...Here are .pdfC++ BinaryTree Help  Creating main function for Trees...Here are .pdf
C++ BinaryTree Help Creating main function for Trees...Here are .pdfforecastfashions
 
MAINCPP include ltiostreamgt include ltstringgt u.pdf
MAINCPP include ltiostreamgt include ltstringgt u.pdfMAINCPP include ltiostreamgt include ltstringgt u.pdf
MAINCPP include ltiostreamgt include ltstringgt u.pdfadityastores21
 
Add these three functions to the class binaryTreeType (provided).W.pdf
Add these three functions to the class binaryTreeType (provided).W.pdfAdd these three functions to the class binaryTreeType (provided).W.pdf
Add these three functions to the class binaryTreeType (provided).W.pdfindiaartz
 
I need help completing this C++ code with these requirements.instr.pdf
I need help completing this C++ code with these requirements.instr.pdfI need help completing this C++ code with these requirements.instr.pdf
I need help completing this C++ code with these requirements.instr.pdfeyeonsecuritysystems
 
Please write in C++ and should be able to compile and debug.Thank yo.pdf
Please write in C++ and should be able to compile and debug.Thank yo.pdfPlease write in C++ and should be able to compile and debug.Thank yo.pdf
Please write in C++ and should be able to compile and debug.Thank yo.pdfajaycosmeticslg
 
(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.pdfarihantmobileselepun
 
Assignment of SOS operating systemThe file lmemman.c has one incom.pdf
Assignment of SOS operating systemThe file lmemman.c has one incom.pdfAssignment of SOS operating systemThe file lmemman.c has one incom.pdf
Assignment of SOS operating systemThe file lmemman.c has one incom.pdfsktambifortune
 
Create an implementation of a binary tree using the recursive appr.pdf
Create an implementation of a binary tree using the recursive appr.pdfCreate an implementation of a binary tree using the recursive appr.pdf
Create an implementation of a binary tree using the recursive appr.pdffederaleyecare
 
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
 
Assignment-6 (2).docx
Assignment-6 (2).docxAssignment-6 (2).docx
Assignment-6 (2).docxkantrajnee88
 
C++, Implement the class BinarySearchTree, as given in listing 16-4 .pdf
C++, Implement the class BinarySearchTree, as given in listing 16-4 .pdfC++, Implement the class BinarySearchTree, as given in listing 16-4 .pdf
C++, Implement the class BinarySearchTree, as given in listing 16-4 .pdfrohit219406
 
write recursive function that calculates and returns the length of a.pdf
write recursive function that calculates and returns the length of a.pdfwrite recursive function that calculates and returns the length of a.pdf
write recursive function that calculates and returns the length of a.pdfarpitcomputronics
 
Point.h header file #ifndef POINT_H #define POINT_H Po.pdf
Point.h header file #ifndef POINT_H #define POINT_H Po.pdfPoint.h header file #ifndef POINT_H #define POINT_H Po.pdf
Point.h header file #ifndef POINT_H #define POINT_H Po.pdfANGELMARKETINGJAIPUR
 
C++ Program to Implement Doubly Linked List #includei.pdf
  C++ Program to Implement Doubly Linked List  #includei.pdf  C++ Program to Implement Doubly Linked List  #includei.pdf
C++ Program to Implement Doubly Linked List #includei.pdfLalkamal2
 
write the To Dos to get the exact outputNOte A valid Fraction .pdf
write the To Dos to get the exact outputNOte A valid Fraction .pdfwrite the To Dos to get the exact outputNOte A valid Fraction .pdf
write the To Dos to get the exact outputNOte A valid Fraction .pdfjyothimuppasani1
 
Need Help with this Java Assignment. Program should be done in JAVA .pdf
Need Help with this Java Assignment. Program should be done in JAVA .pdfNeed Help with this Java Assignment. Program should be done in JAVA .pdf
Need Help with this Java Assignment. Program should be done in JAVA .pdfarchiesgallery
 
Once you have all the structures working as intended- it is time to co.docx
Once you have all the structures working as intended- it is time to co.docxOnce you have all the structures working as intended- it is time to co.docx
Once you have all the structures working as intended- it is time to co.docxfarrahkur54
 
C programming. Answer question only in C code Ninth Deletion with B.pdf
C programming. Answer question only in C code Ninth Deletion with B.pdfC programming. Answer question only in C code Ninth Deletion with B.pdf
C programming. Answer question only in C code Ninth Deletion with B.pdfinfo309708
 

Similar to Templated Binary Tree implementing function help I need to im.pdf (20)

C++ BinaryTree Help Creating main function for Trees...Here are .pdf
C++ BinaryTree Help  Creating main function for Trees...Here are .pdfC++ BinaryTree Help  Creating main function for Trees...Here are .pdf
C++ BinaryTree Help Creating main function for Trees...Here are .pdf
 
MAINCPP include ltiostreamgt include ltstringgt u.pdf
MAINCPP include ltiostreamgt include ltstringgt u.pdfMAINCPP include ltiostreamgt include ltstringgt u.pdf
MAINCPP include ltiostreamgt include ltstringgt u.pdf
 
Add these three functions to the class binaryTreeType (provided).W.pdf
Add these three functions to the class binaryTreeType (provided).W.pdfAdd these three functions to the class binaryTreeType (provided).W.pdf
Add these three functions to the class binaryTreeType (provided).W.pdf
 
I need help completing this C++ code with these requirements.instr.pdf
I need help completing this C++ code with these requirements.instr.pdfI need help completing this C++ code with these requirements.instr.pdf
I need help completing this C++ code with these requirements.instr.pdf
 
Please write in C++ and should be able to compile and debug.Thank yo.pdf
Please write in C++ and should be able to compile and debug.Thank yo.pdfPlease write in C++ and should be able to compile and debug.Thank yo.pdf
Please write in C++ and should be able to compile and debug.Thank yo.pdf
 
C Assignment Help
C Assignment HelpC Assignment Help
C Assignment Help
 
(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
 
Assignment of SOS operating systemThe file lmemman.c has one incom.pdf
Assignment of SOS operating systemThe file lmemman.c has one incom.pdfAssignment of SOS operating systemThe file lmemman.c has one incom.pdf
Assignment of SOS operating systemThe file lmemman.c has one incom.pdf
 
Create an implementation of a binary tree using the recursive appr.pdf
Create an implementation of a binary tree using the recursive appr.pdfCreate an implementation of a binary tree using the recursive appr.pdf
Create an implementation of a binary tree using the recursive appr.pdf
 
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
 
Assignment-6 (2).docx
Assignment-6 (2).docxAssignment-6 (2).docx
Assignment-6 (2).docx
 
C++, Implement the class BinarySearchTree, as given in listing 16-4 .pdf
C++, Implement the class BinarySearchTree, as given in listing 16-4 .pdfC++, Implement the class BinarySearchTree, as given in listing 16-4 .pdf
C++, Implement the class BinarySearchTree, as given in listing 16-4 .pdf
 
write recursive function that calculates and returns the length of a.pdf
write recursive function that calculates and returns the length of a.pdfwrite recursive function that calculates and returns the length of a.pdf
write recursive function that calculates and returns the length of a.pdf
 
Point.h header file #ifndef POINT_H #define POINT_H Po.pdf
Point.h header file #ifndef POINT_H #define POINT_H Po.pdfPoint.h header file #ifndef POINT_H #define POINT_H Po.pdf
Point.h header file #ifndef POINT_H #define POINT_H Po.pdf
 
C++ Program to Implement Doubly Linked List #includei.pdf
  C++ Program to Implement Doubly Linked List  #includei.pdf  C++ Program to Implement Doubly Linked List  #includei.pdf
C++ Program to Implement Doubly Linked List #includei.pdf
 
Workshop Swift
Workshop Swift Workshop Swift
Workshop Swift
 
write the To Dos to get the exact outputNOte A valid Fraction .pdf
write the To Dos to get the exact outputNOte A valid Fraction .pdfwrite the To Dos to get the exact outputNOte A valid Fraction .pdf
write the To Dos to get the exact outputNOte A valid Fraction .pdf
 
Need Help with this Java Assignment. Program should be done in JAVA .pdf
Need Help with this Java Assignment. Program should be done in JAVA .pdfNeed Help with this Java Assignment. Program should be done in JAVA .pdf
Need Help with this Java Assignment. Program should be done in JAVA .pdf
 
Once you have all the structures working as intended- it is time to co.docx
Once you have all the structures working as intended- it is time to co.docxOnce you have all the structures working as intended- it is time to co.docx
Once you have all the structures working as intended- it is time to co.docx
 
C programming. Answer question only in C code Ninth Deletion with B.pdf
C programming. Answer question only in C code Ninth Deletion with B.pdfC programming. Answer question only in C code Ninth Deletion with B.pdf
C programming. Answer question only in C code Ninth Deletion with B.pdf
 

More from manjan6

An introduction and explanation of human factors and sociotechnical .pdf
An introduction and explanation of human factors and sociotechnical .pdfAn introduction and explanation of human factors and sociotechnical .pdf
An introduction and explanation of human factors and sociotechnical .pdfmanjan6
 
Astronomers were able to find a new planet in a far away solar system.pdf
Astronomers were able to find a new planet in a far away solar system.pdfAstronomers were able to find a new planet in a far away solar system.pdf
Astronomers were able to find a new planet in a far away solar system.pdfmanjan6
 
5. If we found AB+ blood at a crime scene and we knew one of our 5 s.pdf
5. If we found AB+ blood at a crime scene and we knew one of our 5 s.pdf5. If we found AB+ blood at a crime scene and we knew one of our 5 s.pdf
5. If we found AB+ blood at a crime scene and we knew one of our 5 s.pdfmanjan6
 
All of the following individuals are U.S. residents Kelly (27.pdf
All of the following individuals are U.S. residents Kelly (27.pdfAll of the following individuals are U.S. residents Kelly (27.pdf
All of the following individuals are U.S. residents Kelly (27.pdfmanjan6
 
Blossom Company had these transactions during the current period..pdf
Blossom Company had these transactions during the current period..pdfBlossom Company had these transactions during the current period..pdf
Blossom Company had these transactions during the current period..pdfmanjan6
 
Using the case study below, develop a written report of your market .pdf
Using the case study below, develop a written report of your market .pdfUsing the case study below, develop a written report of your market .pdf
Using the case study below, develop a written report of your market .pdfmanjan6
 
Which of the following is NOT a characteristic of a plasmid used as .pdf
Which of the following is NOT a characteristic of a plasmid used as .pdfWhich of the following is NOT a characteristic of a plasmid used as .pdf
Which of the following is NOT a characteristic of a plasmid used as .pdfmanjan6
 
What is the evolutionary significance of the amniotic egg Solut.pdf
What is the evolutionary significance of the amniotic egg  Solut.pdfWhat is the evolutionary significance of the amniotic egg  Solut.pdf
What is the evolutionary significance of the amniotic egg Solut.pdfmanjan6
 
What is the role of HTTP What types of objects are transmitted in H.pdf
What is the role of HTTP What types of objects are transmitted in H.pdfWhat is the role of HTTP What types of objects are transmitted in H.pdf
What is the role of HTTP What types of objects are transmitted in H.pdfmanjan6
 
What is the difference between a hash in perl and a hashtable in Jav.pdf
What is the difference between a hash in perl and a hashtable in Jav.pdfWhat is the difference between a hash in perl and a hashtable in Jav.pdf
What is the difference between a hash in perl and a hashtable in Jav.pdfmanjan6
 
What are the specific linkages among immune surveillance, clonal sel.pdf
What are the specific linkages among immune surveillance, clonal sel.pdfWhat are the specific linkages among immune surveillance, clonal sel.pdf
What are the specific linkages among immune surveillance, clonal sel.pdfmanjan6
 
True or False –Paraeducators provide direct or indirect instructio.pdf
True or False –Paraeducators provide direct or indirect instructio.pdfTrue or False –Paraeducators provide direct or indirect instructio.pdf
True or False –Paraeducators provide direct or indirect instructio.pdfmanjan6
 
The situation where the few who yell the loudest get heard Is ref.pdf
The situation where the few who yell the loudest get heard Is ref.pdfThe situation where the few who yell the loudest get heard Is ref.pdf
The situation where the few who yell the loudest get heard Is ref.pdfmanjan6
 
State if you agree or disagree with the question and comments made b.pdf
State if you agree or disagree with the question and comments made b.pdfState if you agree or disagree with the question and comments made b.pdf
State if you agree or disagree with the question and comments made b.pdfmanjan6
 
A number of benefits that one might expect to see from using a datab.pdf
A number of benefits that one might expect to see from using a datab.pdfA number of benefits that one might expect to see from using a datab.pdf
A number of benefits that one might expect to see from using a datab.pdfmanjan6
 
QUESTION If you look at the code, youll see that we keep two list.pdf
QUESTION If you look at the code, youll see that we keep two list.pdfQUESTION If you look at the code, youll see that we keep two list.pdf
QUESTION If you look at the code, youll see that we keep two list.pdfmanjan6
 
Question 11 What is the volume of 17.0 grams of carbon dioxide gas if.pdf
Question 11 What is the volume of 17.0 grams of carbon dioxide gas if.pdfQuestion 11 What is the volume of 17.0 grams of carbon dioxide gas if.pdf
Question 11 What is the volume of 17.0 grams of carbon dioxide gas if.pdfmanjan6
 
Please help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdfPlease help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdfmanjan6
 
Match the enzyme activity in DNA synthesis with its function. DNA po.pdf
Match the enzyme activity in DNA synthesis with its function.  DNA po.pdfMatch the enzyme activity in DNA synthesis with its function.  DNA po.pdf
Match the enzyme activity in DNA synthesis with its function. DNA po.pdfmanjan6
 
Introduction to Engineering ExperimentationSurface temperature con.pdf
Introduction to Engineering ExperimentationSurface temperature con.pdfIntroduction to Engineering ExperimentationSurface temperature con.pdf
Introduction to Engineering ExperimentationSurface temperature con.pdfmanjan6
 

More from manjan6 (20)

An introduction and explanation of human factors and sociotechnical .pdf
An introduction and explanation of human factors and sociotechnical .pdfAn introduction and explanation of human factors and sociotechnical .pdf
An introduction and explanation of human factors and sociotechnical .pdf
 
Astronomers were able to find a new planet in a far away solar system.pdf
Astronomers were able to find a new planet in a far away solar system.pdfAstronomers were able to find a new planet in a far away solar system.pdf
Astronomers were able to find a new planet in a far away solar system.pdf
 
5. If we found AB+ blood at a crime scene and we knew one of our 5 s.pdf
5. If we found AB+ blood at a crime scene and we knew one of our 5 s.pdf5. If we found AB+ blood at a crime scene and we knew one of our 5 s.pdf
5. If we found AB+ blood at a crime scene and we knew one of our 5 s.pdf
 
All of the following individuals are U.S. residents Kelly (27.pdf
All of the following individuals are U.S. residents Kelly (27.pdfAll of the following individuals are U.S. residents Kelly (27.pdf
All of the following individuals are U.S. residents Kelly (27.pdf
 
Blossom Company had these transactions during the current period..pdf
Blossom Company had these transactions during the current period..pdfBlossom Company had these transactions during the current period..pdf
Blossom Company had these transactions during the current period..pdf
 
Using the case study below, develop a written report of your market .pdf
Using the case study below, develop a written report of your market .pdfUsing the case study below, develop a written report of your market .pdf
Using the case study below, develop a written report of your market .pdf
 
Which of the following is NOT a characteristic of a plasmid used as .pdf
Which of the following is NOT a characteristic of a plasmid used as .pdfWhich of the following is NOT a characteristic of a plasmid used as .pdf
Which of the following is NOT a characteristic of a plasmid used as .pdf
 
What is the evolutionary significance of the amniotic egg Solut.pdf
What is the evolutionary significance of the amniotic egg  Solut.pdfWhat is the evolutionary significance of the amniotic egg  Solut.pdf
What is the evolutionary significance of the amniotic egg Solut.pdf
 
What is the role of HTTP What types of objects are transmitted in H.pdf
What is the role of HTTP What types of objects are transmitted in H.pdfWhat is the role of HTTP What types of objects are transmitted in H.pdf
What is the role of HTTP What types of objects are transmitted in H.pdf
 
What is the difference between a hash in perl and a hashtable in Jav.pdf
What is the difference between a hash in perl and a hashtable in Jav.pdfWhat is the difference between a hash in perl and a hashtable in Jav.pdf
What is the difference between a hash in perl and a hashtable in Jav.pdf
 
What are the specific linkages among immune surveillance, clonal sel.pdf
What are the specific linkages among immune surveillance, clonal sel.pdfWhat are the specific linkages among immune surveillance, clonal sel.pdf
What are the specific linkages among immune surveillance, clonal sel.pdf
 
True or False –Paraeducators provide direct or indirect instructio.pdf
True or False –Paraeducators provide direct or indirect instructio.pdfTrue or False –Paraeducators provide direct or indirect instructio.pdf
True or False –Paraeducators provide direct or indirect instructio.pdf
 
The situation where the few who yell the loudest get heard Is ref.pdf
The situation where the few who yell the loudest get heard Is ref.pdfThe situation where the few who yell the loudest get heard Is ref.pdf
The situation where the few who yell the loudest get heard Is ref.pdf
 
State if you agree or disagree with the question and comments made b.pdf
State if you agree or disagree with the question and comments made b.pdfState if you agree or disagree with the question and comments made b.pdf
State if you agree or disagree with the question and comments made b.pdf
 
A number of benefits that one might expect to see from using a datab.pdf
A number of benefits that one might expect to see from using a datab.pdfA number of benefits that one might expect to see from using a datab.pdf
A number of benefits that one might expect to see from using a datab.pdf
 
QUESTION If you look at the code, youll see that we keep two list.pdf
QUESTION If you look at the code, youll see that we keep two list.pdfQUESTION If you look at the code, youll see that we keep two list.pdf
QUESTION If you look at the code, youll see that we keep two list.pdf
 
Question 11 What is the volume of 17.0 grams of carbon dioxide gas if.pdf
Question 11 What is the volume of 17.0 grams of carbon dioxide gas if.pdfQuestion 11 What is the volume of 17.0 grams of carbon dioxide gas if.pdf
Question 11 What is the volume of 17.0 grams of carbon dioxide gas if.pdf
 
Please help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdfPlease help with this. program must be written in C# .. All of the g.pdf
Please help with this. program must be written in C# .. All of the g.pdf
 
Match the enzyme activity in DNA synthesis with its function. DNA po.pdf
Match the enzyme activity in DNA synthesis with its function.  DNA po.pdfMatch the enzyme activity in DNA synthesis with its function.  DNA po.pdf
Match the enzyme activity in DNA synthesis with its function. DNA po.pdf
 
Introduction to Engineering ExperimentationSurface temperature con.pdf
Introduction to Engineering ExperimentationSurface temperature con.pdfIntroduction to Engineering ExperimentationSurface temperature con.pdf
Introduction to Engineering ExperimentationSurface temperature con.pdf
 

Recently uploaded

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
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
 
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
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
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
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
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
 

Recently uploaded (20)

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
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"
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
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
 
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
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
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
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
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
 

Templated Binary Tree implementing function help I need to im.pdf

  • 1. "Templated Binary Tree" implementing function help ? I need to implement header file which i am working on. Void expandExternal and void preorder part : 1. Header File : #ifndef BINARYTREE_H #define BINARYTREE_H #include //////////////////////////////////// // Templated Node Interface /////////////////////////////////// template // base element type class Node { // a node of the tree public: Node() : elt(), par(NULL), left(NULL), right(NULL) { } // constructor private: E elt; // element value Node* par; // parent Node* left; // left child Node* right; // right child template friend class BinaryTree; template friend class Position; }; //////////////////////////////////// // Templated Binary Tree Interface /////////////////////////////////// template // base element type class BinaryTree { public: // public types //Defines a node position class Position {
  • 2. public: Position(Node * _v = NULL) : v(_v) { } // constructor //Returns the element at the position E& operator*() { return v->elt; } //Returns a Position object Position left() const // get left child { return Position(v->left); } //Returns a Position object Position right() const // get right child { return Position(v->right); } //Returns a Position object Position parent() const // get parent { return Position(v->par); } //Returns true or false bool isRoot() const // root of tree? { return v->par == NULL; } //Returns true or false bool isExternal() const // an external node? { return v->left == NULL && v->right == NULL; } //Returns true or false bool isInternal() const // an external node? { return ! isExternal();
  • 3. } private: Node* v; template friend class BinaryTree; };//End Position class definition /* Position List type definition*/ typedef std::list PositionList; public: //Binary member functions BinaryTree() : _root(NULL), n(0) { } ~BinaryTree(); // The destructor need to properly deletes all nodes in the tree to prevent memory leaks. int size() const; // Returns and integer tof the number of nodes. bool empty() const; // Returns a true if the tree is empty else false. Position root() const; // Return the position of the root node. void addRoot(); // Creates and adds the initial root node to the tree this must be added first. void expandExternal(const Position& p); //Expands each external node with a left and right child that are empty. // What goes here? PositionList positions() const; // Returns a std:list of the nodes in the tree call preorder() function. void preorder(Node* v, PositionList& pl) const; // Traversal algorithm for the tree to populate the PositionList // What goes here? private: Node * _root; // pointer to the root int n; // number of nodes }; #endif Thank you Solution for the main function, try writing the code like this : struct Node{
  • 4. Comparable element; Node *left; Node *right; Node(const Comparable & theElement, Node *lt, Node *rt ) : element( theElement ), left( lt ), right( rt ) {} }; // Node{} Node *root; Node * findMin( Node *t ) const; Node * findMax( Node *t ) const;