Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Main.cpp #include <iostream> using namespace std; // General tree node ADT *****

ID: 3813099 • Letter: M

Question

Main.cpp

#include <iostream>
using namespace std;


// General tree node ADT ************************************************************************
template <typename E>
class GTNode
{
private:
   E element;
   GTNode<E> *Parent;
   GTNode<E> *leftChild;
   GTNode<E> *rightSib;


public:

   // Constructor
   GTNode(const E& v)
   {
       Parent = leftChild = rightSib = NULL;
       element = v;
}

   // Constructor
   GTNode(const E& v, GTNode<E>* par)
   { element=v, leftChild=rightSib=NULL, Parent=par;}


   // Return nodes value
   E value() { return element; }


// True if node is a leaf
   bool isLeaf()
{ return leftChild == NULL; }

   // Return node's parent
   GTNode* parent()
{ return Parent; }

   // Return node's first child
GTNode* leftmostChild()
{ return leftChild; }

// Return node's right sibling
GTNode* rightSibling()
{ return rightSib; }

// Set node's value
void setValue(E& val)
{ element = val; }


// Insert as the first child
void insertFirst(GTNode<E>* n)
   {
       n->rightSib = leftChild;
       n->Parent = this;
       leftChild = n;
   }

// Insert as the right sibling
void insertNext(GTNode<E>* n)
   {
       n->rightSib = rightSib;
       n->Parent = Parent;
       rightSib = n;
}

// Remove first child from tree
void removeFirst()
   {
       if (leftChild == NULL) return;
       GTNode<E>* temp = leftChild;
       leftChild = leftChild->rightSib;
       delete temp;
}

// Remove right sibling from tree
void removeNext()
{
       if (rightSib == NULL) return;
       GTNode<E>* temp = rightSib;
       rightSib = rightSib->rightSib;
       delete temp;
}

};

// General tree ADT ************************************************************************
template <typename E>
class GTree
{

private:
   GTNode<E> *root;

   void print_postorder_Help(GTNode<E> *rt)
   {
           // ********** Student code ******************
   }

public:

   // Constructor
   GTree() { root=NULL;}


   // Send all nodes to free store
   void clear() { root = NULL; }


   // Return the root of the tree
   GTNode<E>* Root() { return root; }

   // Combine two trees
void newroot(GTNode<E> *rt)
   {
       clear();
       root=rt;
   }


   int depth(GTNode<E> * t)
   {
           // ********** Student code ******************
   }

   // Print a tree
   void print_postorder() { print_postorder_Help(root); }

};


int main()
{

       // ********** Student code ******************

   /* ======================================= This is an example ====================================================

   //create a Tree
GTree<char> gt;

   //create some node
   GTNode<char> *nA, *nB, *nC, *nD;
   nA= new GTNode<char>('A', NULL);   nB= new GTNode<char>('B', NULL); nC= new GTNode<char>('C', NULL);nD= new GTNode<char>('D', NULL);
   gt.newroot(nA);

   // connect nodes
   nA->insertFirst(nD);
   nA->insertFirst(nC);
   nA->insertFirst(nB);

   // display the tree
   cout<<"The Original Tree: ";
   gt.print_preorder();
   cout<<endl<<endl;

   // display the sequential representation
   cout<<"The Sequential Tree: ";
   gt.print_sequential();

   cout<<endl<<endl;

   ===================================================================================================================== */
}

Assume that you have a tree T that is represented in a binary tree structure as shown by figure 1 root. Figure 1. General Tree T (represented in a binary tree structure) The depth of a node v (distance from root) number of edges from the root to v; alternatively, number of ancestors of v, except itself. (e.g depth of A is 0, depth of B is l) To Do (20 Marks) 1) Download main cpp that contains a c++ implementation of the general tree node ADT and the general tree ADT as it was introduced in class 2) Create your c++ project and add to it the main.cpp that you already downloaded. You will add your code in the source file "main.cpp" 3) Implement in the class GTree the methods

Explanation / Answer

import java.util.Scanner;

/** category GraphColoring **/
public category GraphColoring
non-public int V, numOfColors;
personal int[] color;
personal int[][] graph;

/** operate to assign color **/
public void graphColor(int[][] g, int noc)
answer found **/
if (v == V)
throw new Exception("Solution found");
/** strive all colors **/
for (int c = 1; c &lt;= numOfColors; c++)
  
}
}
/** operate to see if it's valid to allot that color to vertex **/
public Boolean isPossible(int v, int c)
one &amp;&amp; c == color[i])
come false;
come true;
}
/** show resolution **/
public void display()
  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote