Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

THIS IS A MUST FOR THIS PROGRAM Must use recursion in both function (build & pri

ID: 662844 • Letter: T

Question

THIS IS A MUST FOR THIS PROGRAM

Must use recursion in both function (build & print).

HINT : The input data from user will be saved into a string using pars function, use delimiter to extract the integer part and convert them into int by using stoi for the first part in the parentheses. Then directions for where the data to be stored. LLR mean left-left-right node

Main

Void Tree::build (int val, string path)

Void Tree::print ()

-->> data structure you can add to this <<--

Struct Node

{

int data;

Node * left;

Node * right;

};

class Tree

{

public:

Tree(Node * ptr = nullptr) { root = ptr; }

void build(int data, string path);

void print() ;

private:

Node * root;

};

Explanation / Answer

#include<iostream>
#include<string>

using namespace std;
struct Node
{
int data;
Node * left;
Node * right;
};
class Tree
{
public:
Tree(Node * ptr = NULL) { root = ptr; }
void build(int data, string path);
void print() ;
private:
Node * root;
};

void Tree::build (int val, string path){
if(path==""){
cout<<"blank";
}
}
void Tree::print (){}

int main(){
Tree t;
string input;
string data[50];
cout<<"Enter the nodes: ";
cin>>input;
replace(input.begin(),input.end(),'(','');
replace(input.begin(),input.end(),')','');
for(int i=0,j=0;i<input.length();i++){
if(input.at(i)==','){
j+=1;
}else{
data[j].append(input.at(i));
}
}
for(i=0;i<50-1;i++){
t.build(data[i],data[i+1]);
}
}