Question: This code is in Object Oriented Programming but it needs to be in Procedural code. Can someone convert this code from Object Oriented to Procedural

This code is in Object Oriented Programming but it needs to be in Procedural code.

Can someone convert this code from Object Oriented to Procedural code and the header can only contain this one listed below

#include

#inculde

#include

#include

#include

#include

#include

#include

#include

**************The code is written based on this

**I will be using Visual Studio

** Please add comments to functions if possible and please include header file info if used!!

Develop a C++ program that will recursively alphabetize a set of strings in a user-specified file using the tree sort algorithm explained in the lectures whilemaintaining a balanced binary tree at all times.The instructor will test your program with an input file containing: Max Hank Jet Frisky Chata Richard Nan Sam Thomas Karen Gerri Ingrid Alan Dana

When done print out the contents of the tree in inorder in a tabular format similar to the following:

This code is in Object Oriented Programming but it needs to be

The code that needs to be changed

#include

#include

#include

#include

#include

#define pow2(n) (1

using namespace std;

struct node

{

string data;

struct node *lft;

struct node *rght;

}*root;

class avl

{

public:

int theight(node *);

int dif(node *);

node *rr_rot(node *);

node *ll_rot(node *);

node *lr_rot(node *);

node *rl_rot(node *);

node* bal(node *);

node* insrt(node *, string );

void display(node *, int);

void inor(node *);

avl()

{

root = NULL;

}

};

int main()

{

int ch;

string item;

avl avl;

while (1)

{

cout

cout

cout

cout

cout

cin>>ch;

switch(ch)

{

case 1:

cout

cin>>item;

root = avl.insrt(root, item);

break;

case 2:

if (root == NULL)

{

cout

continue;

}

cout

avl.display(root, 1);

break;

case 3:

cout

avl.inor(root);

cout

break;

case 4:

exit(1);

break;

default:

cout

}

}

return 0;

}

/* Height of AVL Tree*/

int avl::theight(node *temp1)

{

int h = 0;

if (temp1 != NULL)

{

int l_height = theight (temp1->lft);

int r_height = theight (temp1->rght);

int max_height = max (l_height, r_height);

h = max_height + 1;

}

return h;

}

/* Finding balance factor of node */

int avl::dif(node *temp1)

{

int l_height = theight (temp1->lft);

int r_height = theight (temp1->rght);

int balfact= l_height - r_height;

return balfact;

}

/* Right- Right Rotation of AVL Tree*/

node *avl::rr_rot(node *tparent)

{

node *temp1;

temp1 = tparent->rght;

tparent->rght = temp1->lft;

temp1->lft = tparent;

return temp1;

}

/*Left- Left Rotation of AVL Tree*/

node *avl::ll_rot(node *tparent)

{

node *temp1;

temp1 = tparent->lft;

tparent->lft = temp1->rght;

temp1->rght = tparent;

return temp1;

}

/* Left - Right Rotation of AVL Tree */

node *avl::lr_rot(node *tparent)

{

node *temp1;

temp1 = tparent->lft;

tparent->lft = rr_rot (temp1);

return ll_rot (tparent);

}

/*Right- Left Rotation of AVL Tree*/

node *avl::rl_rot(node *tparent)

{

node *temp1;

temp1 = tparent->rght;

tparent->rght = ll_rot (temp1);

return rr_rot (tparent);

}

/*AVL Tree Balancing*/

node *avl::bal(node *temp1)

{

int bal_factor = dif (temp1);

if (bal_factor > 1)

{

if (dif (temp1->lft) > 0)

temp1 = ll_rot (temp1);

else

temp1 = lr_rot (temp1);

}

else if (bal_factor

{

if (dif (temp1->rght) > 0)

temp1 = rl_rot (temp1);

else

temp1 = rr_rot (temp1);

}

return temp1;

}

/*Insertion of values*/

node *avl::insrt(node *root, string value)

{

if (root == NULL)

{

root = new node;

root->data = value;

root->lft = NULL;

root->rght = NULL;

return root;

}

else if (value data)

{

root->lft = insrt(root->lft, value);

root = bal (root);

}

else if (value >= root->data)

{

root->rght = insrt(root->rght, value);

root = bal (root);

}

return root;

}

/* Display of the AVL Tree*/

void avl::display(node *ptr, int level)

{

int i;

if (ptr!=NULL)

{

display(ptr->rght, level + 1);

printf(" ");

if (ptr == root)

cout ";

for (i = 0; i

cout

cout

display(ptr->lft, level + 1);

}

}

/*Inorder Traversal of the AVL Tree*/

void avl::inor(node *tre)

{

if (tre == NULL)

return;

inor (tre->lft);

cout

inor (tre->rght);

}

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!