Question: The code below is the data structure of a tree that our professor built in class. #include typedef long int myint; class Frac { private:

The code below is the data structure of a tree that our professor built in class.

#include

typedef long int myint; class Frac { private: myint num; myint den; public: Frac(const myint& = 0, const myint& = 1); Frac(const Frac&); void operator=(const Frac&); myint getNum() const; myint getDen() const; void setNum(const myint &); void setDen(const myint &); myint operator(const Frac &) const;

}; Frac::Frac(const myint& _num, const myint &_den) { num = _num; den = _den; if (den == 0) { num = 0; den = 1; } if (den(const Frac &_cW) const { if (num * _cW.getDen() > den * _cW.getNum()) { return 1; } return 0; }

class TNode { public: Frac value; TNode * lChild; TNode * rChild; TNode(); }; TNode::TNode() { lChild = nullptr; rChild = nullptr; } void insert(TNode*& root, const Frac& fr) { if (root == nullptr) { root = new TNode; root->value = fr; } else { if (frvalue) { insert(root->lChild, fr); } if (fr>root->value) { insert(root->rChild, fr); } } } void insert(TNode*& root, const int& b, const int&c = 1) { Frac fr(b, c); insert(root, fr); } void deleteNode(TNode*& root) { if (root != nullptr) { if (root->lChild != nullptr) { TNode *helper = root->lChild; if (helper->rChild != nullptr) { TNode *h2 = helper->rChild; while (h2->rChild != nullptr) { helper = helper->rChild; h2 = h2->rChild; } root->value = h2->value; if (h2->lChild == nullptr) { delete h2; helper->rChild = nullptr; } else { deleteNode(h2); } } else { root->value = helper->value; if (helper->lChild == nullptr) {

delete helper; root->lChild = nullptr; } else { deleteNode(helper); } }

} else { if (root->rChild != nullptr) { TNode *helper = root->rChild; if (helper->lChild != nullptr) { TNode *h2 = helper->lChild; while (h2->lChild != nullptr) { helper = helper->lChild; h2 = h2->lChild; } root->value = h2->value; if (h2->rChild == nullptr) { delete h2; helper->lChild = nullptr; } else { deleteNode(h2); } } else { root->value = helper->value; if (helper->rChild == nullptr) {

delete helper; root->rChild = nullptr; } else { deleteNode(helper); } }

} else { delete root; root = nullptr; } } } }

myint deleteValue(TNode *&root, const Frac &fr) { if (root == nullptr) { return 0; } if (frvalue) { return deleteValue(root->lChild, fr); } if (fr>root->value) { return deleteValue(root->rChild, fr); } deleteNode(root); return 1; }

void printAll(TNode * root) { if (root != nullptr) { printAll(root->lChild); std::cout value).getNum(); std::cout value).getDen(); std::cout rChild); } }

The code below is the data structure of a tree that our

professor built in class. #include typedef long int myint; class Frac {

int main(){ myint a,b,c; Frac tempFr; SetOfFractions setF; a=1; while(a!=0){ std::cout>a; if(a==1){ std::cout>b>>c; tempFr.setNum(b); tempFr.setDen(c); setF.insertInS(tempFr); } if(a==2){ std::cout>b>>c; tempFr.setNum(b); tempFr.setDen(c); std::cout Homework Problem 1 Using the data structure of a tree that we built in class, create a class SetofFractions with the following declaration. class setof Fractions H private TNode root public setof Fractions, CO; setoff Fractions (const setofFractions & Setoff Fractions (SetofFractions &&) void operator (const Setof Fractions &D void operator (SetofFractions &&); myint is Element Cconst Frac & Const; myint insertins (const Frac &); void printAllFractions O const; ~Setof Fractions C); Ca The default constructor SetofFractionsO should initialize an empty tree. The copy constructor SetofFractions(const Setof Fractions & copyFrom) should create the set of fractions with the same elements as the set copyFrom. Make sure that the elements are not shared so if later elements are changed in copyFrom the changes do not affect the objects created using copy constructor (b) Copy void operator the content of the set overthe existing elements. Make sure you properly deallocate the memory before copying to prevent memory leak

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!