#include<iostream>
using namespace std;
class BiTree {
public:
class Node
{
public:
Node():lchild(nullptr),rchild(nullptr){};
int data;
class Node *lchild,*rchild;
};
typedef Node* NodePointer;
public:
void CreateBiTree();
BiTree()
{
root = new Node;
root->data = 0;
};
protected:
NodePointer root;
};
void BiTree::CreateBiTree()
{
Node *temp = new Node;
temp = root;
int key;
cout << "please input the number which you can choose insert to leftchild or right child: 1 left, 2 right ,other quit ";
cin>>key;
switch (key)
{
case 1:
{
int m;
cout << " please input data";
while (cin >>m)
{
Node *newNode = new Node;
newNode->data = m;
temp->lchild = newNode;
temp = newNode;
}
}break;
case 2:
{
}break;
default:
break;
}
}
int main ()
{
BiTree root;
root.CreateBiTree();
return 0;
}二叉樹的創建的部分實現及二叉樹結構的定義
C++實現二叉樹
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.