I'm not sure what i'm doing wrong, any help would be great.
main.cpp(58): error C3861: 'preOrederHelper': identifier not found
main.cpp(53) : while compiling class template member function 'void tree<T>::preOrderHelper(treeNode<T> *) const'
with
[
T=int
]
main.cpp(9) : while compiling class template member function 'tree<T>::tree(void)'
with
[
T=int
]
main.cpp(103) : see reference to class template instantiation 'tree<T>' being compiled
with
[
T=int
main.cpp(77): error C3861: 'inOrderHellper': identifier not found
main.cpp(72) : while compiling class template member function 'void tree<T>::inOrderHelper(treeNode<T> *) const'
with
[
T=int
]
//treenode.h
#ifndef TREENODE_H
#define TREENODE_H
template<typename T>class tree;
template<typename T>
class treeNode
{
friend class tree<T>;
public:
//constructor
treeNode(const T &d) : left(0), right(0), data(d) {}
T getData() const
{
return data;
}
private:
treeNode<T> *left;
T data;
treeNode<T> *right;
};
#endif
//tree.h
#ifndef TREE_H
#define TREE_H
#include "treenode.h"
template<typename T>
class tree
{
public:
tree();
void insertNode(const T &);
void preOrderTraversal() const;
void inOrderTraversal() const;
void postOrderTraversal() const;
private:
treeNode<T> *root;
//utility functions
void insertNodeHelper(treeNode<T> **, const T &);
void preOrderHelper(treeNode<T> *) const;
void inOrderHelper(treeNode<T> *) const;
void postOrderHelper(treeNode<T> *) const;
};
//main.cpp
#include <iostream>
#include <conio.h>
#include "tree.h"
using namespace std;
//constructor
template<typename T>
tree<T>::tree()
{
root = 0;
}
//insert node in tree
template<typename T>
void tree<T>::insertNode(const T &value)
{
insertNodeHelper(&root, value);
}
//utility function called by insertNode; receives a pointer
//to a pointer so that the function can modify pointer's value
template<typename T>
void tree<T>::insertNodeHelper(treeNode<T> **ptr, const T &value)
{
//if subtree is empty, create a new treeNode containing value
if(*ptr == 0)
*ptr = new treeNode<T>(value);
else
{
//subtree is not empty
if(value < (*ptr)->data)
insertNodeHelper(&((*ptr)->left), value);
else
{
if(value > (*ptr)->data)
insertNodeHelper(&((*ptr)->right), value);
else
cout << value << " dup" << endl;
}
}
}
//begin preorder traversal of tree
template<typename T>
void tree<T>::preOrderTraversal() const
{
preOrderHelper(root);
}
//utility function to perform preorder traversal of tree
template<typename T>
void tree<T>::preOrderHelper(treeNode<T> *ptr) const
{
if(ptr != 0)
{
cout << ptr->data << ' ';
preOrderHelper(ptr->left);
preOrederHelper(ptr->right);
}
}
//begin inordertraversal of tree
template<typename T>
void tree<T>::inOrderTraversal() const
{
inOrderHelper(root);
}
//utility function to perform inorder traversal of tree
template<typename T>
void tree<T>::inOrderHelper(treeNode<T> *ptr) const
{
if(ptr != 0)
{
inOrderHelper(ptr->left);
cout << ptr->data << ' ';
inOrderHellper(ptr->right);
}
}
//begin post order traversal of tree
template<typename T>
void tree<T>::postOrderTraversal() const
{
postOrderHelper(root);
}
//utility function to perform postorder traversal of tree
template<typename T>
void tree<T>::postOrderHelper(treeNode<T> *ptr) const
{
if(ptr != 0)
{
postOrderHelper(ptr->left);
postOrderHelper(ptr->right);
cout << ptr->data << ' ';
}
}
int main()
{
tree<int> intTree;
int intValue;
cout << "Enter 10 integer values: " << endl;
for(int i = 0; i < 10; i++)
{
cin >> intValue;
intTree.insertNode(intValue);
}
cout << endl << endl;
cout << "Preorder traversal\n";
intTree.preOrderTraversal();
cout << "\nInOrder traversal\n";
intTree.inOrderTraversal();
cout << "\nPostOrder traversal\n";
intTree.postOrderTraversal();
_getch();
return 0;
}