Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started