64,647
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string> // --------------------------加这个
using namespace std;
template <typename T>
class tnode
{
public:
T nodeValue;
tnode<T> *left, *right;
tnode() {left = NULL; right = NULL;} // --------------------left,right初始化
tnode(const T& item,tnode<T> *lptr = NULL,tnode<T> *rptr = NULL)
{ // --------------------nodeValue,left,right初始化
nodeValue = item;
left = NULL;
right = NULL;
}
};
template <typename T>
void inorderOutput(tnode<T> *t,const string& separator = " ")
{
if(t != NULL)
{
inorderOutput<T>(t->left, separator);
cout << t->nodeValue << separator;
inorderOutput<T>(t->right, separator);
}
}
int main()
{
tnode<int> *p,*q,*r = NULL;
p = new tnode<int>(8);
q = new tnode<int>(20);
r = new tnode<int>(1,p,q);
inorderOutput<int>(r,"haha");
}