Question: Please I want This program to be rewritten in the most simplest form but accurate and able to compile and run so please help me.

Please I want This program to be rewritten in the most simplest form but accurate and able to compile and run so please help me.

#include

#include

#include

using namespace std;

#define COUNT 10

struct node {

public:

string data;

node* leftChild;

node* rightChild;

};

class BST{

public:

node* insert (node*, string);

void print2DUtil(node*,int);

void print2D (node*);

};

node* Newnode(string f){

node*temp = new node;

temp ->data =f;

temp -> rightChild= NULL;

temp -> leftChild= NULL;

return temp;

}

node* BST::insert (node* root,string data){

if (root==NULL){

root = Newnode (data);

}

else if (data<=root->data){

root -> rightChild = insert(root ->rightChild, data);

}

else

{

root->leftChild = insert(root->leftChild , data);

}

return root;

}

void BST:: print2DUtil(node *root, int space)

{

if (root == NULL)

return;

space += COUNT;

print2DUtil(root->rightChild, space);

cout<

for (int i = COUNT; i < space; i++)

cout<<" ";

cout<<"/"<data<<" ";

print2DUtil(root->leftChild, space);

cout <

}

void BST:: print2D(node *root)

{

print2DUtil(root, 0);

}

int main (){

int option;

string element;

BST B;

node* root =NULL;

do {

cout << "Please select an operation, or enter 0 if you wish to leave the Program" << endl;

cout << "1.-> Insert a file" << endl;

cout << "2.->Display the files " <

cin >>option;

switch(option){

case 1 : cout << "Enter the file name : ";

cin >> element;

root = B.insert(root , element);

break;

case 2 : B.print2D(root);

}

}

while (option!=0);

cout<<"End of Program" <

return 0;

}

The program compiles and run but my professor want us to rewrite in a shorter and simplest form and it should run and compile as well without any error

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!