二叉树的实现(定义,创建,遍历),求救

来源:百度知道 编辑:UC知道 时间:2024/05/30 12:06:59
RT..
主要是完整,可以在C++里运行。
百度好多回了,没搞懂,请用最简单的例子调试好了再回答吧。
高分请教。

以前编的程序,有前序遍历的非递归
#include<iostream>
#include<list>
using namespace std;

class binarytreenode //树的节点定义
{
public:
int number;
binarytreenode *left;
binarytreenode *right;

binarytreenode(int a=0,binarytreenode *first=0,binarytreenode *second=0)
{
number=a;
left=first;
right=second;
}
};

class stack //栈的定义
{
private:
list<binarytreenode *> lst;

public:
stack()
{};
void push(binarytreenode *el)
{
lst.push_back(el);
}
binarytreenode *pop()
{
binarytreenode *el=lst.back();
lst.pop_back();
return el;
}
bool isEmpty()
{
return lst.empty();
}
};

class binarytree //树的定义
{
public:
binarytreenode *root;
binarytree(binarytreenode *a=0)
{
root=a;
}
void insert(int a);