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;
===================================================================================================================== */
}
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 <= numOfColors; c++)
}
}
/** operate to see if it's valid to allot that color to vertex **/
public Boolean isPossible(int v, int c)
one && c == color[i])
come false;
come true;
}
/** show resolution **/
public void display()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.