<数据结构>二叉树的实现
2017-01-02 14:50
627 查看
#include<iostream> using namespace std; struct BiNode { int data; BiNode *rchild, *lchild; }; class BiTree { public: void createtree(); void preorder(); private: BiNode *root; void Create(BiNode* &bt);//注意必须有& void printnode(BiNode* T); }; void BiTree::printnode(BiNode* T) { if (T){ cout << T->data << endl; printnode(T->lchild); printnode(T->rchild); } } void BiTree::preorder() { printnode(root); } void BiTree::createtree() { cout << "请输入根节点:" << endl; Create(root); if (NULL != root) { cout << "root=" << root->data << endl; } else { cout << "The BinaryTree is empty." << endl; } } void BiTree::Create(BiNode* &bt) { int ch; cin >> ch; if (ch == 0)bt = NULL; else { bt = new BiNode; bt->data = ch; cout << "调用左孩子" << endl; Create(bt->lchild); cout << "调用右孩子" << endl; Create(bt->rchild); } } int main() { BiTree m; m.createtree(); m.preorder(); return 0; }
相关文章推荐
- <剑指offer 面试题7-1>构建二叉树以及实现遍历 Java
- <二叉树 前中后 层序 非递归遍历 c语言实现>
- 数据结构-->二叉树的链式实现 ADT
- <转载>在.NET中基于Windows消息的IPC实现
- <<字符串高级截取和统计>>一文的C#正则实现
- Python笔记——几种数据结构的实现:栈、队列及二叉树
- 数据结构_树_二叉树的建立、遍历、复制与移除_二叉链表存储_C++实现
- <转载>SQLITE中原子提交的实现
- 数据结构C语言实现系列——二叉树
- 【数据结构】二叉树基本操作的程序实现
- <转>java实现MP3解码器和迷你播放器
- 数据结构_树_二叉树的线索化_C++实现
- 数据结构:二叉树的建立和遍历(C#实现)
- <摘>C#,MFC,Win32——实现系统级热键
- <@乌龟:>手动实现C语言运行库(1) 堆内存分配,malloc and free
- 数据结构的Java实现——二叉树
- <转>如何C#中实现在TreeView查找某一节点
- 利用HTML的<meta>实现页面跳转
- <转载>让.NET Remoting更快些-IPCChannel的实现
- 简单数据结构的实现之二叉树