### General Tree

How can I transform my number output into letters by implementing general tree
A
/\
B C D E F G
/ \ \ \
[H] [IJ] [KLM] [N]
/\
[PQ]
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123`` ``````#include using namespace std; struct Node { int key; vectorchild; }; Node *newNode(int key) { Node *temp = new Node; temp->key = key; return temp; } void LevelOrderTraversal(Node * root) { if (root==NULL) return; queue q; q.push(root); while (!q.empty()) { int n = q.size(); while (n > 0) { Node * p = q.front(); q.pop(); cout << p->key << " "; for (int i=0; ichild.size(); i++) q.push(p->child[i]); n--; } cout << endl; } } int main() { Node *root = newNode('A'); (root->child).push_back(newNode('B')); (root->child).push_back(newNode('C')); (root->child).push_back(newNode('D')); (root->child).push_back(newNode('E')); (root->child).push_back(newNode('F')); (root->child).push_back(newNode('G')); (root->child[0]->child).push_back(newNode('H')); (root->child[0]->child).push_back(newNode('I')); (root->child[2]->child).push_back(newNode('J')); (root->child[3]->child).push_back(newNode('K')); (root->child[3]->child).push_back(newNode('L')); (root->child[3]->child).push_back(newNode('M')); (root->child[3]->child).push_back(newNode('N')); LevelOrderTraversal(root); return 0; }``````
Last edited on
 ``` A /\ B C D E F G / \ \ \ [H] [IJ][KLM][N] /\ [PQ] ```
Last edited on
Topic archived. No new replies allowed.