traversal function

Hello,
I was trying to Write a traversal function named displayTree that will build up a string of characters from the table in a particular order so that the unit test of buildTree will pass the test.

Here is what i have so far. I am not sure what to do next and the assignment is due today. Please help me
main.cpp

#define CATCH_CONFIG_MAIN
#include <iostream>
#ifdef UNIT_TEST
#include "catch.hpp"
#endif // UNIT_TEST
#include "table.h"

Tnode *Telegraph::root=0;

void Telegraph:: addTNode(char c, Tnode *node, Tnode *& refNode) {
std:: cout << "harsh" <<std::endl;
if (c == '-') {
node->left = refNode;
//refNode->left = node;
std:: cout << "founddd -" <<std::endl;
} else if (c == '.') {
node->right = refNode;
std:: cout << "found _" <<std::endl;
}


}

{
std::string Telegraph:: displayTree()
void Preorder(struct TNode *root)
{


if(root == NULL) return;

printf("%c ",root->symbol);
Preorder(root ->left);
Preorder(root ->right);

}
return "-.-";
}


void Telegraph::buildTree()
{
Tnode *node, *nextNode; int i; char*dd;
root = new Tnode; if (!root ) return;
root->symbol = ' ';
for (i=0; table [i].symbol; i++)
{
node =root;
for (dd=table[i] . code; *dd; dd++)
{
addTNode (*dd, node, nextNode);
node=nextNode;
} node-> symbol = table[i].symbol;
}
}


#ifndef UNIT_TEST
int main()
{
Telegraph:: buildTree();
std:: cout <<Telegraph::displayTree() <<std::endl;

}
#endif // UNIT_TEST
#ifdef UNIT_TEST
using Catch::Matchers::Equals;

TEST_CASE ("Morse Code")
{
Telegraph::buildTree();
std:: string s= Telegraph::displayTreee();
std:: string t= "5H4SV39FU?**2E;R*.*APWJ1 6BDXNYCKYT7Z*, GQM8*09*O"
REQUIRE (s==t);
}
#endif


table.h
#pragma once
#include "telegraph.h"

MorseCode Telegraph::table[] = {
{'A', ".-"}, {'B', "-..."}, {'C', "-.-."}, {'D', "-.."},
{'E', "."}, {'F', "..-."}, {'G', "--."}, {'H', "...."},
{'I', ".."}, {'J', ".---"}, {'K', "-.-"}, {'L', ".-.."},
{'M', "--"}, {'N', "-."}, {'O', "---"}, {'P', ".--."},
{'Q', "--.-"}, {'R', ".-."}, {'S', "..."}, {'T', "-"},
{'U', "..-"}, {'V', "...-"}, {'W', ".--"}, {'X', "-..-"},
{'Y', "-.--"}, {'Z', "--.."},
{'0', "-----"}, {'1', ".----"}, {'2', "..---"}, {'3', "...--"},
{'4', "....-"}, {'5', "....."}, {'6', "-...."}, {'7', "--..."},
{'8', "---.."}, {'9', "----."},
{'.', ".-.-.-"}, {',', "--..--"}, {'?', "..--.."},
{'\0', ""} // END
};


telegraph.h


#pragma once
#include <string>
struct MorseCode
{
char symbol;
char* code;
};
struct Tnode
{
char symbol;
Tnode *left;
Tnode *right;

Tnode() { // Constructor
symbol = '*';
left =
right = 0;
}
};
class Telegraph
{
public:
static Tnode * root;
static MorseCode table[];
static void buildTree();
static std::string displayTree();
static void addTNode(char c, Tnode *node, Tnode *& refNode);
};
Topic archived. No new replies allowed.