SlideShare a Scribd company logo
I have a Programming is Binary Tree Search (BTS) for strings with pointers, but I do not know
how to change BTS for strings using arrays.
Can you help me to change the method, please?
This is programming:
#include
#include
#include
using namespace std;
struct myNode
{
string data;
struct myNode *lNode;
struct myNode *rNode;
} *roNode;
class myBTS
{
public:
void seek(string, myNode **, myNode **);
void add(myNode *, myNode*);
void rem(string);
void caseOne(myNode *, myNode *);
void caseTwo(myNode *, myNode *);
void caseThree(myNode *, myNode *);
void print(myNode *, char);
myBTS()
{
roNode = NULL;
}
};
// Main method
int main ()
{
int myOptions;
string rData;
myBTS mybst;
myNode *tmp;
while (1)
{
cout << "-----------------------------------------" << endl;
cout << "Welcome to Binary Search Tree Programming" << endl;
cout << "-----------------------------------------" << endl;
cout << "1. Add Data " << endl;
cout << "2. Remove Data " << endl;
cout << "3. Print Data " << endl;
cout << "4. Exit " << endl;
cout << "Enter Option : ";
cin >> myOptions;
switch(myOptions)
{
case 1:
tmp = new myNode;
cout << "Enter data to add : ";
cin >> tmp->data;
mybst.add(roNode, tmp);
break;
case 2:
if (roNode == NULL)
{
cout << "Tree empty!!!" << endl;
continue;
}
else
{
cout << "Enter data to remove: ";
cin >> rData;
mybst.rem(rData);
}
break;
case 3:
cout << "Print Tree:" << endl;
mybst.print(roNode,1);
cout << endl;
break;
case 4:
exit (1);
default:
cout << "Wrong Option!!!" << endl;
}
}
}
// Data in BTS
void myBTS::seek(string sData, myNode **myPar, myNode **myLoc)
{
myNode *ptr1, *ptr2;
if (roNode == NULL)
{
*myLoc = NULL;
*myPar = NULL;
return;
}
if (sData == roNode-> data)
{
*myLoc = roNode;
*myPar = NULL;
return;
}
if (sData < roNode-> data)
ptr1 = roNode->lNode;
else
ptr1 = roNode-> rNode;
ptr2 = roNode;
while (ptr1 != NULL)
{
if (sData == ptr1->data)
{
*myLoc = ptr1;
*myPar = ptr2;
return;
}
ptr2 = ptr1;
if (sData < ptr1 -> data)
ptr1 = ptr1 ->lNode;
else
ptr1 = ptr1 -> rNode;
}
*myLoc = NULL;
*myPar = ptr2;
}
// Add Data into BTS
void myBTS::add(myNode *myTree, myNode *myNewNode)
{
if (roNode == NULL)
{
roNode = new myNode;
roNode -> data = myNewNode ->data;
roNode -> lNode = NULL;
roNode -> rNode = NULL;
cout << "Root data is added successfully" << endl;
return;
}
if (myTree -> data == myNewNode -> data)
{
cout << "Data already in BTS" << endl;
return;
}
if (myTree -> data > myNewNode -> data)
{
if (myTree ->lNode != NULL)
{
add (myTree -> lNode, myNewNode);
}
else
{
myTree -> lNode = myNewNode;
(myTree -> lNode) -> lNode = NULL;
(myTree -> lNode) -> rNode = NULL;
cout << "Data added to the Left successfully" << endl;
return;
}
}
if (myTree -> rNode != NULL)
{
add(myTree -> rNode, myNewNode);
}
else
{
myTree -> rNode = myNewNode;
(myTree -> rNode) -> lNode = NULL;
(myTree -> rNode) -> rNode = NULL;
cout << "Data added to the Right successfully" << endl;
return;
}
}
//Remove data from BTS
void myBTS:: rem(string sData)
{
myNode *myParent, *myLocation;
if (roNode == NULL)
{
cout << "Empty BTS" << endl;
return;
}
seek (sData, &myParent, &myLocation);
if (myLocation == NULL)
{
cout << "Data not in BTS" << endl;
return;
}
if (myLocation -> lNode == NULL && myLocation -> rNode == NULL)
caseOne (myParent, myLocation);
if (myLocation -> lNode != NULL && myLocation -> rNode == NULL)
caseTwo (myParent, myLocation);
if (myLocation -> lNode == NULL && myLocation -> rNode != NULL)
caseTwo (myParent, myLocation);
if (myLocation -> lNode != NULL && myLocation -> rNode != NULL)
caseTwo (myParent, myLocation);
free(myLocation);
}
// Case One
void myBTS:: caseOne (myNode *myPar, myNode *myLoc)
{
if (myPar == NULL)
{
roNode = NULL;
}
else
{
if (myLoc == myPar -> lNode)
myPar -> lNode = NULL;
else
myPar -> rNode = NULL;
}
}
// Case Two
void myBTS:: caseTwo (myNode *myPar, myNode *myLoc)
{
myNode *child;
if (myLoc -> lNode != NULL)
child = myLoc -> lNode;
else
child = myLoc -> rNode;
if (myPar == NULL)
{
roNode = child;
}
else
{
if (myLoc == myPar -> lNode)
myPar -> lNode = child;
else
myPar -> rNode = child;
}
}
// Case Three
void myBTS:: caseThree (myNode *myPar, myNode *myLoc)
{
myNode *ptr1, *ptr2, *successor, *parsuccessor;
ptr2 = myLoc;
ptr1 = myLoc -> rNode;
while (ptr1 -> lNode != NULL)
{
ptr2 = ptr1;
ptr1 = ptr1 -> lNode;
}
successor = ptr1;
parsuccessor = ptr2;
if (successor -> lNode == NULL && successor -> rNode == NULL)
caseOne(parsuccessor, successor);
else
caseTwo(parsuccessor, successor);
if (myPar == NULL)
{
roNode = successor;
}
else
{
if (myLoc == myPar -> lNode)
myPar -> lNode = successor;
else
myPar -> rNode = successor;
}
successor -> lNode = myLoc -> lNode;
successor -> rNode = myLoc -> rNode;
}
// Display Tree Structure
void myBTS::print(myNode *ptr1, char myLevel)
{
int i;
if (ptr1 != NULL)
{
print (ptr1 -> rNode, myLevel+1);
cout << endl;
if (ptr1 == roNode)
cout << "Root-->: ";
else
{
for (i = 0; i < myLevel; i++)
cout << " ";
}
cout << ptr1 -> data;
print (ptr1-> lNode, myLevel+1);
}
}
Solution

More Related Content

Similar to I have a Programming is Binary Tree Search (BTS) for strings with po.pdf (20)

PDF
Data StructuresPlease I need help completing this c++ program..pdf
arkleatheray
 
PDF
main.cpp#include TreeNode.h GIVEN void inorderTraversal(.pdf
pratikradia365
 
PDF
Tree Traversals A tree traversal is the process of visiting.pdf
ajayadinathcomputers
 
PDF
C++, Implement the class BinarySearchTree, as given in listing 16-4 .pdf
rohit219406
 
PPTX
Binary Search Tree.pptxA binary search i
prashant Lastkumar
 
PDF
Write a C++ program that implements a binary search tree (BST) to man.pdf
hardjasonoco14599
 
PDF
in this assignment you are asked to write a simple driver program an.pdf
michardsonkhaicarr37
 
PDF
Please write the C++ code that would display the exact same output a.pdf
amarndsons
 
PDF
8 chapter4 trees_bst
SSE_AndyLi
 
PDF
I have C++ question that I do not know how to do, Can you teach me t.pdf
fasttrackscardecors
 
PPTX
Binary search tree.pptx
Santhiya S
 
PDF
Tree and binary tree
Zaid Shabbir
 
PPT
Unit 4 tree
kalyanineve
 
PDF
Define a class template for an AVL tree. Create an object of su.pdf
eyelineoptics
 
PDF
Can you finish and write the int main for the code according to the in.pdf
aksachdevahosymills
 
DOCX
10 Solution#include-iostream-h- #include-conio-h- #include-process-h-.docx
todd991
 
PDF
AnswerThe new program with the required constructor and with a te.pdf
nipuns1983
 
PDF
Complete DB code following the instructions Implement the D.pdf
access2future1
 
PPTX
TREE DATA STRUCTURE SLIDES dsa dsa .pptx
asimshahzad8611
 
PPTX
UNIT 2 TREES & GRAPH COMPLETE NOTES OF DATA STRUCTURE
sahadevbkbiet2023
 
Data StructuresPlease I need help completing this c++ program..pdf
arkleatheray
 
main.cpp#include TreeNode.h GIVEN void inorderTraversal(.pdf
pratikradia365
 
Tree Traversals A tree traversal is the process of visiting.pdf
ajayadinathcomputers
 
C++, Implement the class BinarySearchTree, as given in listing 16-4 .pdf
rohit219406
 
Binary Search Tree.pptxA binary search i
prashant Lastkumar
 
Write a C++ program that implements a binary search tree (BST) to man.pdf
hardjasonoco14599
 
in this assignment you are asked to write a simple driver program an.pdf
michardsonkhaicarr37
 
Please write the C++ code that would display the exact same output a.pdf
amarndsons
 
8 chapter4 trees_bst
SSE_AndyLi
 
I have C++ question that I do not know how to do, Can you teach me t.pdf
fasttrackscardecors
 
Binary search tree.pptx
Santhiya S
 
Tree and binary tree
Zaid Shabbir
 
Unit 4 tree
kalyanineve
 
Define a class template for an AVL tree. Create an object of su.pdf
eyelineoptics
 
Can you finish and write the int main for the code according to the in.pdf
aksachdevahosymills
 
10 Solution#include-iostream-h- #include-conio-h- #include-process-h-.docx
todd991
 
AnswerThe new program with the required constructor and with a te.pdf
nipuns1983
 
Complete DB code following the instructions Implement the D.pdf
access2future1
 
TREE DATA STRUCTURE SLIDES dsa dsa .pptx
asimshahzad8611
 
UNIT 2 TREES & GRAPH COMPLETE NOTES OF DATA STRUCTURE
sahadevbkbiet2023
 

More from ARCHANASTOREKOTA (20)

PDF
Please help! Computer Science C++ programming code needed.Thank yo.pdf
ARCHANASTOREKOTA
 
PDF
Please Answer, will rate! Exercise 1 - Classifying financial stateme.pdf
ARCHANASTOREKOTA
 
PDF
Need 2 -3 paragraphConsidering the aesthetics of the late 19th cen.pdf
ARCHANASTOREKOTA
 
PDF
Match each statement to the most appropriate choices. More than one .pdf
ARCHANASTOREKOTA
 
PDF
List three sources of variability in material properties. If that va.pdf
ARCHANASTOREKOTA
 
PDF
Need the fill in the blank questions answeredSolution1) CamboB.pdf
ARCHANASTOREKOTA
 
PDF
making and testing a prediction suppose that after 22 months, gupp.pdf
ARCHANASTOREKOTA
 
PDF
Life is wholly dependent on water. List and discuss two reasons why .pdf
ARCHANASTOREKOTA
 
PDF
John Rawls argued that societys goal should be to lessen the welfar.pdf
ARCHANASTOREKOTA
 
PDF
In Exercises 19-24, find the volume of the solid generated by revolvi.pdf
ARCHANASTOREKOTA
 
PDF
In which step of meiosis, the members of tetra separate Solutio.pdf
ARCHANASTOREKOTA
 
PDF
Identify the distinguishing characteristics of member of Phylum Cnid.pdf
ARCHANASTOREKOTA
 
PDF
If most evolutionary change occurs during and immediately after spec.pdf
ARCHANASTOREKOTA
 
PDF
Imagine that someone picking up roses in a garden gets a scratch fro.pdf
ARCHANASTOREKOTA
 
PDF
I need help working out this question . woman has normal vision al.pdf
ARCHANASTOREKOTA
 
PDF
How is ATP produced in mammalian cells under aerobic conditions1..pdf
ARCHANASTOREKOTA
 
PDF
How con osmosis work for and against homeostasis How do osmosis .pdf
ARCHANASTOREKOTA
 
PDF
Enzymes and KE. Whats the relationship in terms of substrate mo.pdf
ARCHANASTOREKOTA
 
PDF
Explain membranes. Include the definition and name the four types an.pdf
ARCHANASTOREKOTA
 
PDF
Define1. Reciprocal cross –2. True or pure-breeding –Fill in t.pdf
ARCHANASTOREKOTA
 
Please help! Computer Science C++ programming code needed.Thank yo.pdf
ARCHANASTOREKOTA
 
Please Answer, will rate! Exercise 1 - Classifying financial stateme.pdf
ARCHANASTOREKOTA
 
Need 2 -3 paragraphConsidering the aesthetics of the late 19th cen.pdf
ARCHANASTOREKOTA
 
Match each statement to the most appropriate choices. More than one .pdf
ARCHANASTOREKOTA
 
List three sources of variability in material properties. If that va.pdf
ARCHANASTOREKOTA
 
Need the fill in the blank questions answeredSolution1) CamboB.pdf
ARCHANASTOREKOTA
 
making and testing a prediction suppose that after 22 months, gupp.pdf
ARCHANASTOREKOTA
 
Life is wholly dependent on water. List and discuss two reasons why .pdf
ARCHANASTOREKOTA
 
John Rawls argued that societys goal should be to lessen the welfar.pdf
ARCHANASTOREKOTA
 
In Exercises 19-24, find the volume of the solid generated by revolvi.pdf
ARCHANASTOREKOTA
 
In which step of meiosis, the members of tetra separate Solutio.pdf
ARCHANASTOREKOTA
 
Identify the distinguishing characteristics of member of Phylum Cnid.pdf
ARCHANASTOREKOTA
 
If most evolutionary change occurs during and immediately after spec.pdf
ARCHANASTOREKOTA
 
Imagine that someone picking up roses in a garden gets a scratch fro.pdf
ARCHANASTOREKOTA
 
I need help working out this question . woman has normal vision al.pdf
ARCHANASTOREKOTA
 
How is ATP produced in mammalian cells under aerobic conditions1..pdf
ARCHANASTOREKOTA
 
How con osmosis work for and against homeostasis How do osmosis .pdf
ARCHANASTOREKOTA
 
Enzymes and KE. Whats the relationship in terms of substrate mo.pdf
ARCHANASTOREKOTA
 
Explain membranes. Include the definition and name the four types an.pdf
ARCHANASTOREKOTA
 
Define1. Reciprocal cross –2. True or pure-breeding –Fill in t.pdf
ARCHANASTOREKOTA
 
Ad

Recently uploaded (20)

PDF
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PPTX
Controller Request and Response in Odoo18
Celine George
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PDF
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
Quarter 1_PPT_PE & HEALTH 8_WEEK 3-4.pptx
ronajadolpnhs
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PPTX
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
Controller Request and Response in Odoo18
Celine George
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
Quarter 1_PPT_PE & HEALTH 8_WEEK 3-4.pptx
ronajadolpnhs
 
Dimensions of Societal Planning in Commonism
StefanMz
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
Characteristics, Strengths and Weaknesses of Quantitative Research.pdf
Thelma Villaflores
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
Ad

I have a Programming is Binary Tree Search (BTS) for strings with po.pdf

  • 1. I have a Programming is Binary Tree Search (BTS) for strings with pointers, but I do not know how to change BTS for strings using arrays. Can you help me to change the method, please? This is programming: #include #include #include using namespace std; struct myNode { string data; struct myNode *lNode; struct myNode *rNode; } *roNode; class myBTS { public: void seek(string, myNode **, myNode **); void add(myNode *, myNode*); void rem(string); void caseOne(myNode *, myNode *); void caseTwo(myNode *, myNode *); void caseThree(myNode *, myNode *); void print(myNode *, char); myBTS() { roNode = NULL; } }; // Main method int main () { int myOptions; string rData; myBTS mybst;
  • 2. myNode *tmp; while (1) { cout << "-----------------------------------------" << endl; cout << "Welcome to Binary Search Tree Programming" << endl; cout << "-----------------------------------------" << endl; cout << "1. Add Data " << endl; cout << "2. Remove Data " << endl; cout << "3. Print Data " << endl; cout << "4. Exit " << endl; cout << "Enter Option : "; cin >> myOptions; switch(myOptions) { case 1: tmp = new myNode; cout << "Enter data to add : "; cin >> tmp->data; mybst.add(roNode, tmp); break; case 2: if (roNode == NULL) { cout << "Tree empty!!!" << endl; continue; } else { cout << "Enter data to remove: "; cin >> rData; mybst.rem(rData); } break; case 3: cout << "Print Tree:" << endl; mybst.print(roNode,1);
  • 3. cout << endl; break; case 4: exit (1); default: cout << "Wrong Option!!!" << endl; } } } // Data in BTS void myBTS::seek(string sData, myNode **myPar, myNode **myLoc) { myNode *ptr1, *ptr2; if (roNode == NULL) { *myLoc = NULL; *myPar = NULL; return; } if (sData == roNode-> data) { *myLoc = roNode; *myPar = NULL; return; } if (sData < roNode-> data) ptr1 = roNode->lNode; else ptr1 = roNode-> rNode; ptr2 = roNode; while (ptr1 != NULL) { if (sData == ptr1->data) { *myLoc = ptr1;
  • 4. *myPar = ptr2; return; } ptr2 = ptr1; if (sData < ptr1 -> data) ptr1 = ptr1 ->lNode; else ptr1 = ptr1 -> rNode; } *myLoc = NULL; *myPar = ptr2; } // Add Data into BTS void myBTS::add(myNode *myTree, myNode *myNewNode) { if (roNode == NULL) { roNode = new myNode; roNode -> data = myNewNode ->data; roNode -> lNode = NULL; roNode -> rNode = NULL; cout << "Root data is added successfully" << endl; return; } if (myTree -> data == myNewNode -> data) { cout << "Data already in BTS" << endl; return; } if (myTree -> data > myNewNode -> data) { if (myTree ->lNode != NULL) { add (myTree -> lNode, myNewNode); } else
  • 5. { myTree -> lNode = myNewNode; (myTree -> lNode) -> lNode = NULL; (myTree -> lNode) -> rNode = NULL; cout << "Data added to the Left successfully" << endl; return; } } if (myTree -> rNode != NULL) { add(myTree -> rNode, myNewNode); } else { myTree -> rNode = myNewNode; (myTree -> rNode) -> lNode = NULL; (myTree -> rNode) -> rNode = NULL; cout << "Data added to the Right successfully" << endl; return; } } //Remove data from BTS void myBTS:: rem(string sData) { myNode *myParent, *myLocation; if (roNode == NULL) { cout << "Empty BTS" << endl; return; } seek (sData, &myParent, &myLocation); if (myLocation == NULL) { cout << "Data not in BTS" << endl; return;
  • 6. } if (myLocation -> lNode == NULL && myLocation -> rNode == NULL) caseOne (myParent, myLocation); if (myLocation -> lNode != NULL && myLocation -> rNode == NULL) caseTwo (myParent, myLocation); if (myLocation -> lNode == NULL && myLocation -> rNode != NULL) caseTwo (myParent, myLocation); if (myLocation -> lNode != NULL && myLocation -> rNode != NULL) caseTwo (myParent, myLocation); free(myLocation); } // Case One void myBTS:: caseOne (myNode *myPar, myNode *myLoc) { if (myPar == NULL) { roNode = NULL; } else { if (myLoc == myPar -> lNode) myPar -> lNode = NULL; else myPar -> rNode = NULL; } } // Case Two void myBTS:: caseTwo (myNode *myPar, myNode *myLoc) { myNode *child; if (myLoc -> lNode != NULL) child = myLoc -> lNode; else child = myLoc -> rNode; if (myPar == NULL) {
  • 7. roNode = child; } else { if (myLoc == myPar -> lNode) myPar -> lNode = child; else myPar -> rNode = child; } } // Case Three void myBTS:: caseThree (myNode *myPar, myNode *myLoc) { myNode *ptr1, *ptr2, *successor, *parsuccessor; ptr2 = myLoc; ptr1 = myLoc -> rNode; while (ptr1 -> lNode != NULL) { ptr2 = ptr1; ptr1 = ptr1 -> lNode; } successor = ptr1; parsuccessor = ptr2; if (successor -> lNode == NULL && successor -> rNode == NULL) caseOne(parsuccessor, successor); else caseTwo(parsuccessor, successor); if (myPar == NULL) { roNode = successor; } else { if (myLoc == myPar -> lNode) myPar -> lNode = successor; else
  • 8. myPar -> rNode = successor; } successor -> lNode = myLoc -> lNode; successor -> rNode = myLoc -> rNode; } // Display Tree Structure void myBTS::print(myNode *ptr1, char myLevel) { int i; if (ptr1 != NULL) { print (ptr1 -> rNode, myLevel+1); cout << endl; if (ptr1 == roNode) cout << "Root-->: "; else { for (i = 0; i < myLevel; i++) cout << " "; } cout << ptr1 -> data; print (ptr1-> lNode, myLevel+1); } } Solution