SlideShare a Scribd company logo
1 of 4
Download to read offline
Answer:
The new program with the required constructor and with a test is given below
Code:
#include
#include
using namespace std;
class TNode
{
public:
int data;
TNode *left;
TNode *right;
TNode(int n){ data = n; left = right = 0; }
TNode(int n, TNode *left, TNode *right)
{
data = n;
//Assign the left node address and right node address with the parameters passed
this->left = left;
this->right = right;
}
};
void printTree(TNode *t)
{
if (!t) return;
printTree(t->left);
cout << t->data << " ";
printTree(t->right);
}
void search_for(int n, TNode *t)
{
cout << "Searhing for " << n << endl;
while (t)
{
cout << "looking at " << t->data << endl;
if (t->data == n)
{
cout << "Found it!";
return;
}
if (n < t->data)
{
cout << "Going left ";
t = t->left;
}
else
{
cout << "Going right ";
t = t->right;
}
}
cout << "Can't find it";
}
// Creates a two node tree
int main()
{
TNode *root = 0;
root = new TNode(5);
cout << root->data << endl;
TNode *one_node = new TNode(1);
TNode *three_node = new TNode(3);
//use the new constructor
TNode *two_node = new TNode(2, one_node, three_node);
root->left = new TNode(3);
printTree(root);
cout << endl;
search_for(3, root);
getchar();
return 0;
}
Solution
Answer:
The new program with the required constructor and with a test is given below
Code:
#include
#include
using namespace std;
class TNode
{
public:
int data;
TNode *left;
TNode *right;
TNode(int n){ data = n; left = right = 0; }
TNode(int n, TNode *left, TNode *right)
{
data = n;
//Assign the left node address and right node address with the parameters passed
this->left = left;
this->right = right;
}
};
void printTree(TNode *t)
{
if (!t) return;
printTree(t->left);
cout << t->data << " ";
printTree(t->right);
}
void search_for(int n, TNode *t)
{
cout << "Searhing for " << n << endl;
while (t)
{
cout << "looking at " << t->data << endl;
if (t->data == n)
{
cout << "Found it!";
return;
}
if (n < t->data)
{
cout << "Going left ";
t = t->left;
}
else
{
cout << "Going right ";
t = t->right;
}
}
cout << "Can't find it";
}
// Creates a two node tree
int main()
{
TNode *root = 0;
root = new TNode(5);
cout << root->data << endl;
TNode *one_node = new TNode(1);
TNode *three_node = new TNode(3);
//use the new constructor
TNode *two_node = new TNode(2, one_node, three_node);
root->left = new TNode(3);
printTree(root);
cout << endl;
search_for(3, root);
getchar();
return 0;
}

More Related Content

Similar to AnswerThe new program with the required constructor and with a te.pdf

Write code in c++ Program to a topological sort on a graph Program pl.docx
Write code in c++ Program to a topological sort on a graph  Program pl.docxWrite code in c++ Program to a topological sort on a graph  Program pl.docx
Write code in c++ Program to a topological sort on a graph Program pl.docxnoreendchesterton753
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfEricvtJFraserr
 
C++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxC++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxBrianGHiNewmanv
 
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
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfJUSTSTYLISH3B2MOHALI
 
#include iostream #include deque #include stdio.h   scan.pdf
#include iostream #include deque #include stdio.h   scan.pdf#include iostream #include deque #include stdio.h   scan.pdf
#include iostream #include deque #include stdio.h   scan.pdfanandmobile
 
#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docxajoy21
 
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfDoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfaathiauto
 
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdfAssignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdffortmdu
 
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
 
In C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdfIn C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdffantoosh1
 
Modify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfModify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfmallik3000
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklistritu1806
 
Help with the following code1. Rewrite to be contained in a vecto.pdf
Help with the following code1. Rewrite to be contained in a vecto.pdfHelp with the following code1. Rewrite to be contained in a vecto.pdf
Help with the following code1. Rewrite to be contained in a vecto.pdfezzi97
 
C++ adt c++ implementations
C++   adt c++ implementationsC++   adt c++ implementations
C++ adt c++ implementationsRex Mwamba
 
Write a C program that reads the words the user types at the command.pdf
Write a C program that reads the words the user types at the command.pdfWrite a C program that reads the words the user types at the command.pdf
Write a C program that reads the words the user types at the command.pdfSANDEEPARIHANT
 

Similar to AnswerThe new program with the required constructor and with a te.pdf (20)

Binary Tree
Binary  TreeBinary  Tree
Binary Tree
 
Write code in c++ Program to a topological sort on a graph Program pl.docx
Write code in c++ Program to a topological sort on a graph  Program pl.docxWrite code in c++ Program to a topological sort on a graph  Program pl.docx
Write code in c++ Program to a topological sort on a graph Program pl.docx
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
 
C++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxC++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docx
 
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
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdf
 
DS Code (CWH).docx
DS Code (CWH).docxDS Code (CWH).docx
DS Code (CWH).docx
 
#include iostream #include deque #include stdio.h   scan.pdf
#include iostream #include deque #include stdio.h   scan.pdf#include iostream #include deque #include stdio.h   scan.pdf
#include iostream #include deque #include stdio.h   scan.pdf
 
#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx
 
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfDoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
 
Lab-2.4 101.pdf
Lab-2.4 101.pdfLab-2.4 101.pdf
Lab-2.4 101.pdf
 
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdfAssignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.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
 
In C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdfIn C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdf
 
Modify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfModify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdf
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
 
Help with the following code1. Rewrite to be contained in a vecto.pdf
Help with the following code1. Rewrite to be contained in a vecto.pdfHelp with the following code1. Rewrite to be contained in a vecto.pdf
Help with the following code1. Rewrite to be contained in a vecto.pdf
 
Ds 2 cycle
Ds 2 cycleDs 2 cycle
Ds 2 cycle
 
C++ adt c++ implementations
C++   adt c++ implementationsC++   adt c++ implementations
C++ adt c++ implementations
 
Write a C program that reads the words the user types at the command.pdf
Write a C program that reads the words the user types at the command.pdfWrite a C program that reads the words the user types at the command.pdf
Write a C program that reads the words the user types at the command.pdf
 

More from nipuns1983

0.5164Solution0.5164.pdf
0.5164Solution0.5164.pdf0.5164Solution0.5164.pdf
0.5164Solution0.5164.pdfnipuns1983
 
#include stdio.h #include stdlib.h #include unistd.h .pdf
 #include stdio.h #include stdlib.h #include unistd.h .pdf #include stdio.h #include stdlib.h #include unistd.h .pdf
#include stdio.h #include stdlib.h #include unistd.h .pdfnipuns1983
 
Thalamus acts as the gateway to the cerebral cortex. It is situated .pdf
  Thalamus acts as the gateway to the cerebral cortex. It is situated .pdf  Thalamus acts as the gateway to the cerebral cortex. It is situated .pdf
Thalamus acts as the gateway to the cerebral cortex. It is situated .pdfnipuns1983
 
ADH causes increased permeability of DCT and collecting tubule to wa.pdf
  ADH causes increased permeability of DCT and collecting tubule to wa.pdf  ADH causes increased permeability of DCT and collecting tubule to wa.pdf
ADH causes increased permeability of DCT and collecting tubule to wa.pdfnipuns1983
 
There are several solutions for treating chronically mentally ill pa.pdf
There are several solutions for treating chronically mentally ill pa.pdfThere are several solutions for treating chronically mentally ill pa.pdf
There are several solutions for treating chronically mentally ill pa.pdfnipuns1983
 
The water is split providing the electrons for PSII, which then exci.pdf
The water is split providing the electrons for PSII, which then exci.pdfThe water is split providing the electrons for PSII, which then exci.pdf
The water is split providing the electrons for PSII, which then exci.pdfnipuns1983
 
The Sarbanes-Oxlet act (SOX) was primarily enacted following the Enr.pdf
The Sarbanes-Oxlet act (SOX) was primarily enacted following the Enr.pdfThe Sarbanes-Oxlet act (SOX) was primarily enacted following the Enr.pdf
The Sarbanes-Oxlet act (SOX) was primarily enacted following the Enr.pdfnipuns1983
 
The integral has a pole at z=-1Integral region is around a circle .pdf
The integral has a pole at z=-1Integral region is around a circle .pdfThe integral has a pole at z=-1Integral region is around a circle .pdf
The integral has a pole at z=-1Integral region is around a circle .pdfnipuns1983
 
SolutionThis encryption scheme is not considered to be a secure o.pdf
SolutionThis encryption scheme is not considered to be a secure o.pdfSolutionThis encryption scheme is not considered to be a secure o.pdf
SolutionThis encryption scheme is not considered to be a secure o.pdfnipuns1983
 
Smart Beta ia a rather elusive term in modern finance sometimes know.pdf
Smart Beta ia a rather elusive term in modern finance sometimes know.pdfSmart Beta ia a rather elusive term in modern finance sometimes know.pdf
Smart Beta ia a rather elusive term in modern finance sometimes know.pdfnipuns1983
 
Ques-1 What is the differential diagnosis of this patients infectin.pdf
Ques-1 What is the differential diagnosis of this patients infectin.pdfQues-1 What is the differential diagnosis of this patients infectin.pdf
Ques-1 What is the differential diagnosis of this patients infectin.pdfnipuns1983
 
package employeeType.employee;public abstract class Employee {  .pdf
package employeeType.employee;public abstract class Employee {  .pdfpackage employeeType.employee;public abstract class Employee {  .pdf
package employeeType.employee;public abstract class Employee {  .pdfnipuns1983
 
Option 1Project management software Project management software .pdf
Option 1Project management software Project management software .pdfOption 1Project management software Project management software .pdf
Option 1Project management software Project management software .pdfnipuns1983
 
import java.util.Scanner;public class InputIntegers{public sta.pdf
import java.util.Scanner;public class InputIntegers{public sta.pdfimport java.util.Scanner;public class InputIntegers{public sta.pdf
import java.util.Scanner;public class InputIntegers{public sta.pdfnipuns1983
 
The main drawback of Troutons rule is that it i.pdf
                     The main drawback of Troutons rule is that it i.pdf                     The main drawback of Troutons rule is that it i.pdf
The main drawback of Troutons rule is that it i.pdfnipuns1983
 
Solid to liquid, or liquid to gas change absorbs .pdf
                     Solid to liquid, or liquid to gas change absorbs .pdf                     Solid to liquid, or liquid to gas change absorbs .pdf
Solid to liquid, or liquid to gas change absorbs .pdfnipuns1983
 
RNase P catalyzes the Mg2+-dependent 5-maturati.pdf
                     RNase P catalyzes the Mg2+-dependent 5-maturati.pdf                     RNase P catalyzes the Mg2+-dependent 5-maturati.pdf
RNase P catalyzes the Mg2+-dependent 5-maturati.pdfnipuns1983
 
pH of a solution is directly proportional to mola.pdf
                     pH of a solution is directly proportional to mola.pdf                     pH of a solution is directly proportional to mola.pdf
pH of a solution is directly proportional to mola.pdfnipuns1983
 
Option - D is correct !! .pdf
                     Option - D is correct !!                         .pdf                     Option - D is correct !!                         .pdf
Option - D is correct !! .pdfnipuns1983
 
n = number present before orbital =3 l= 0 for s, .pdf
                     n = number present before orbital =3 l= 0 for s, .pdf                     n = number present before orbital =3 l= 0 for s, .pdf
n = number present before orbital =3 l= 0 for s, .pdfnipuns1983
 

More from nipuns1983 (20)

0.5164Solution0.5164.pdf
0.5164Solution0.5164.pdf0.5164Solution0.5164.pdf
0.5164Solution0.5164.pdf
 
#include stdio.h #include stdlib.h #include unistd.h .pdf
 #include stdio.h #include stdlib.h #include unistd.h .pdf #include stdio.h #include stdlib.h #include unistd.h .pdf
#include stdio.h #include stdlib.h #include unistd.h .pdf
 
Thalamus acts as the gateway to the cerebral cortex. It is situated .pdf
  Thalamus acts as the gateway to the cerebral cortex. It is situated .pdf  Thalamus acts as the gateway to the cerebral cortex. It is situated .pdf
Thalamus acts as the gateway to the cerebral cortex. It is situated .pdf
 
ADH causes increased permeability of DCT and collecting tubule to wa.pdf
  ADH causes increased permeability of DCT and collecting tubule to wa.pdf  ADH causes increased permeability of DCT and collecting tubule to wa.pdf
ADH causes increased permeability of DCT and collecting tubule to wa.pdf
 
There are several solutions for treating chronically mentally ill pa.pdf
There are several solutions for treating chronically mentally ill pa.pdfThere are several solutions for treating chronically mentally ill pa.pdf
There are several solutions for treating chronically mentally ill pa.pdf
 
The water is split providing the electrons for PSII, which then exci.pdf
The water is split providing the electrons for PSII, which then exci.pdfThe water is split providing the electrons for PSII, which then exci.pdf
The water is split providing the electrons for PSII, which then exci.pdf
 
The Sarbanes-Oxlet act (SOX) was primarily enacted following the Enr.pdf
The Sarbanes-Oxlet act (SOX) was primarily enacted following the Enr.pdfThe Sarbanes-Oxlet act (SOX) was primarily enacted following the Enr.pdf
The Sarbanes-Oxlet act (SOX) was primarily enacted following the Enr.pdf
 
The integral has a pole at z=-1Integral region is around a circle .pdf
The integral has a pole at z=-1Integral region is around a circle .pdfThe integral has a pole at z=-1Integral region is around a circle .pdf
The integral has a pole at z=-1Integral region is around a circle .pdf
 
SolutionThis encryption scheme is not considered to be a secure o.pdf
SolutionThis encryption scheme is not considered to be a secure o.pdfSolutionThis encryption scheme is not considered to be a secure o.pdf
SolutionThis encryption scheme is not considered to be a secure o.pdf
 
Smart Beta ia a rather elusive term in modern finance sometimes know.pdf
Smart Beta ia a rather elusive term in modern finance sometimes know.pdfSmart Beta ia a rather elusive term in modern finance sometimes know.pdf
Smart Beta ia a rather elusive term in modern finance sometimes know.pdf
 
Ques-1 What is the differential diagnosis of this patients infectin.pdf
Ques-1 What is the differential diagnosis of this patients infectin.pdfQues-1 What is the differential diagnosis of this patients infectin.pdf
Ques-1 What is the differential diagnosis of this patients infectin.pdf
 
package employeeType.employee;public abstract class Employee {  .pdf
package employeeType.employee;public abstract class Employee {  .pdfpackage employeeType.employee;public abstract class Employee {  .pdf
package employeeType.employee;public abstract class Employee {  .pdf
 
Option 1Project management software Project management software .pdf
Option 1Project management software Project management software .pdfOption 1Project management software Project management software .pdf
Option 1Project management software Project management software .pdf
 
import java.util.Scanner;public class InputIntegers{public sta.pdf
import java.util.Scanner;public class InputIntegers{public sta.pdfimport java.util.Scanner;public class InputIntegers{public sta.pdf
import java.util.Scanner;public class InputIntegers{public sta.pdf
 
The main drawback of Troutons rule is that it i.pdf
                     The main drawback of Troutons rule is that it i.pdf                     The main drawback of Troutons rule is that it i.pdf
The main drawback of Troutons rule is that it i.pdf
 
Solid to liquid, or liquid to gas change absorbs .pdf
                     Solid to liquid, or liquid to gas change absorbs .pdf                     Solid to liquid, or liquid to gas change absorbs .pdf
Solid to liquid, or liquid to gas change absorbs .pdf
 
RNase P catalyzes the Mg2+-dependent 5-maturati.pdf
                     RNase P catalyzes the Mg2+-dependent 5-maturati.pdf                     RNase P catalyzes the Mg2+-dependent 5-maturati.pdf
RNase P catalyzes the Mg2+-dependent 5-maturati.pdf
 
pH of a solution is directly proportional to mola.pdf
                     pH of a solution is directly proportional to mola.pdf                     pH of a solution is directly proportional to mola.pdf
pH of a solution is directly proportional to mola.pdf
 
Option - D is correct !! .pdf
                     Option - D is correct !!                         .pdf                     Option - D is correct !!                         .pdf
Option - D is correct !! .pdf
 
n = number present before orbital =3 l= 0 for s, .pdf
                     n = number present before orbital =3 l= 0 for s, .pdf                     n = number present before orbital =3 l= 0 for s, .pdf
n = number present before orbital =3 l= 0 for s, .pdf
 

Recently uploaded

Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
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
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
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
 
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
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 

Recently uploaded (20)

Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.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
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
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
 
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
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 

AnswerThe new program with the required constructor and with a te.pdf

  • 1. Answer: The new program with the required constructor and with a test is given below Code: #include #include using namespace std; class TNode { public: int data; TNode *left; TNode *right; TNode(int n){ data = n; left = right = 0; } TNode(int n, TNode *left, TNode *right) { data = n; //Assign the left node address and right node address with the parameters passed this->left = left; this->right = right; } }; void printTree(TNode *t) { if (!t) return; printTree(t->left); cout << t->data << " "; printTree(t->right); } void search_for(int n, TNode *t) { cout << "Searhing for " << n << endl; while (t) { cout << "looking at " << t->data << endl;
  • 2. if (t->data == n) { cout << "Found it!"; return; } if (n < t->data) { cout << "Going left "; t = t->left; } else { cout << "Going right "; t = t->right; } } cout << "Can't find it"; } // Creates a two node tree int main() { TNode *root = 0; root = new TNode(5); cout << root->data << endl; TNode *one_node = new TNode(1); TNode *three_node = new TNode(3); //use the new constructor TNode *two_node = new TNode(2, one_node, three_node); root->left = new TNode(3); printTree(root); cout << endl; search_for(3, root); getchar(); return 0; }
  • 3. Solution Answer: The new program with the required constructor and with a test is given below Code: #include #include using namespace std; class TNode { public: int data; TNode *left; TNode *right; TNode(int n){ data = n; left = right = 0; } TNode(int n, TNode *left, TNode *right) { data = n; //Assign the left node address and right node address with the parameters passed this->left = left; this->right = right; } }; void printTree(TNode *t) { if (!t) return; printTree(t->left); cout << t->data << " "; printTree(t->right); } void search_for(int n, TNode *t) { cout << "Searhing for " << n << endl; while (t) {
  • 4. cout << "looking at " << t->data << endl; if (t->data == n) { cout << "Found it!"; return; } if (n < t->data) { cout << "Going left "; t = t->left; } else { cout << "Going right "; t = t->right; } } cout << "Can't find it"; } // Creates a two node tree int main() { TNode *root = 0; root = new TNode(5); cout << root->data << endl; TNode *one_node = new TNode(1); TNode *three_node = new TNode(3); //use the new constructor TNode *two_node = new TNode(2, one_node, three_node); root->left = new TNode(3); printTree(root); cout << endl; search_for(3, root); getchar(); return 0; }