Question: In c + + , help me fix this codes output as its very strange and a delete function ( prompt:Delete length characters from the

In c++, help me fix this codes output as its very strange and a delete function(prompt:Delete length characters from the Rope starting from start. You can do this by spliting the rope into three, divided by start and start+length characters and deleting everything in the middle.) and a substring function (prompt: Return the substring that starts at character position i and goes to character position j
. Do this by finding the node u that contains the i-th character where weight(u) is greater than or equal to j Then do an in-order traversal of tree starting at u.
code:
#include
using namespace std;
const int LEAF_LEN =2;
class Rope
{
public:
Rope* left, * right, * parent;
char* str;
int lCount;
};
void createRopeStructure(Rope*& node, Rope* par,
char a[], int l, int r)
{
Rope* tmp = new Rope();
tmp->left = tmp->right = NULL;
tmp->parent = par;
if ((r - l)> LEAF_LEN)
{
tmp->str = NULL;
tmp->lCount =(r - l)/2;
node = tmp;
int m =(l + r)/2;
createRopeStructure(node->left, node, a, l, m);
createRopeStructure(node->right, node, a, m +1, r);
}
else
{
node = tmp;
tmp->lCount =(r - l);
int j =0;
tmp->str = new char[LEAF_LEN];
for (int i = l; i <= r; i++)
tmp->str[j++]= a[i];
}
}
void printstring(Rope* r)
{
if (r == NULL)
return;
if (r->left == NULL && r->right == NULL)
cout << r->str;
printstring(r->left);
printstring(r->right);
}
void concatenate(Rope*& root3, Rope* root1, Rope* root2, int n1)
{
Rope* tmp = new Rope();
tmp->parent = NULL;
tmp->left = root1;
tmp->right = root2;
root1->parent = root2->parent = tmp;
tmp->lCount = n1;
tmp->str = NULL;
root3= tmp;
}
void deleted(int i, int j, Rope*& root2){
for (; i <= j; i++)
{
//root2[i]='';
}
}
int main()
{
Rope* root1= NULL;
char a[]="Hi ";
int n1= sizeof(a)/ sizeof(a[0]);
createRopeStructure(root1, NULL, a,0, n1-1);
Rope* root2= NULL;
char b[]= "How are you";
int n2= sizeof(b)/ sizeof(b[0]);
createRopeStructure(root2, NULL, b,0, n2-1);
Rope* root3= NULL;
concatenate(root3, root1, root2, n1);
printstring(root3);
cout << endl;
return 0;
deleted(n1-1, n2-1, root3);
}

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 Finance Questions!