Hi,
Can some one tell me whats wrong with following program.
Following program is to create binary tree.
I tryed this program on Solaris and getting following compile time error.
"createTree.cpp", line 18: Error: Node* is not a structure type.
"createTree.cpp", line 19: Error: Node* is not a structure type.
"createTree.cpp", line 20: Error: Node* is not a structure type.
The program is :
**********************************************************
#include <iostream.h>
#include <stdio.h>
class Node;
class Tree ;
static Node* getNode();
class Node
{
public :
int value;
Node *left;
Node *right;
Node(int val)
{
this.left = NULL;
this.right = NULL;
this.value = val;
}
static Node* getNode()
{
cout << " Node value ? " ;
int val;
cin >> val;
Node *n= new Node(val);
return (n);
}
};
class Tree
{
Node* root;
void preorder(Node* head)
{
cout << " " << head->value;
preorder(head->left);
preorder(head->right);
}
public :
Tree():root(NULL)
{
root = getNode();
getMoreElements(root);
}
void getMoreElements( Node* head)
{
bool boolVal;
cout << " Do Node(" << head->value << ") have left subtree ? " << endl ;
cin >> boolVal;
if (boolVal)
{
head->left = getNode(); //new Node();
getMoreElements(head->left);
}
cout << " Do Node(" << head->value << ") have right subtree ? " << endl
;
cin >> boolVal;
if (boolVal)
{
head->right = getNode(); //new Node();
getMoreElements(head->right);
}
}
void printTree()
{
preorder(root);
}
};
**********************************************************
[Non-text portions of this message have been removed]