关于二叉树的一些心得

#include
#include
#include
#include

using namespace std;

typedef struct bitnode
{

int val;
struct bitnode* lchild, * rchild;

}bitnode,*bitree;

struct ReturnTypeOne
{

bool isBST;
int _min;
int _max;

};

struct ReturnTypeTwo
{

bool isAVL;
int height;
ReturnTypeTwo(bool _isAVL, int _height)
{
    isAVL = _isAVL;
    height = _height;
}

};

int StringToInt(string s)
{

int num = 0;
for (int i = 0; i < s.size(); i++)
{
    num = num * 10 + s[i] - '0';
}
return num;

}

int preValue = INT_MIN;

//构建一颗二叉树
bitree createBitree(int level)
{

string s;
cout << "this is the " << level << "th's bitnode:" << endl;
cin >> s;
if (s == "n") {
	return nullptr;
}
else {
	int x = StringToInt(s);
	
	bitree node = new bitnode;

	node->val = x;
	node->lchild = createBitree(level + 1);
	node->rchild = createBitree(level + 1);
	return node;
}

}

//递归的先序遍历
void preOrder(bitree node)
{
if (!node) return;

cout << node->val << ' ';
preOrder(node->lchild);
preOrder(node->rchild);

}

//非递归的先序遍历
void PreOrder(bitree node)
{


你可能感兴趣的:(深度优先,链表,c++,算法)