二叉树数组存储结构实现
来源:互联网 发布:史诗音乐知乎 编辑:程序博客网 时间:2024/06/07 02:37
不是满二叉树的话非常浪费空间,一般就在堆排序中用了,写这个一般操作纯粹是因为坑爹的软设作业= =
#ifndef arrayBinaryTree_H_#define arrayBinaryTree_H_#define maxsize 1000#include <iostream>#include <stack>#include <cstdlib>#include <cstring>using namespace std;class arrayBinaryTree{private: int num; char node[maxsize];public: arrayBinaryTree(); //~arrayBinaryTree(); void creat(); void preOrder();};arrayBinaryTree::arrayBinaryTree(){ cout<<"please input the num of the node(include the empty node)"<<endl; cin>>num;}void arrayBinaryTree::creat(){ memset(node,'#',sizeof(node)); int i; for(i=0; i<num; i++) { cin>>node[i]; }}void arrayBinaryTree::preOrder(){ int temp; stack<int>S; S.push(0); while(!S.empty()) { temp=S.top(); S.pop(); cout<<node[temp]<<" "; int lchild=temp*2+1; int rchild=temp*2+2; if(node[rchild]!='#') S.push(rchild); if(node[lchild]!='#') S.push(lchild); }}#endif
测试:
#include <iostream>#include "arrayBinaryTree.h"using namespace std;int main(){ //input //31 //A#B##CD####EF#G################ arrayBinaryTree test; test.creat(); test.preOrder(); return 0;}
- 二叉树数组存储结构实现
- 二叉树的存储结构和实现
- 二叉树-----数组存储结构及操作算法的实现------堆排序
- 大话数据结构十四:二叉树的顺序存储结构(数组实现)
- 二叉树存储结构
- 二叉树的链式存储结构 C++代码实现
- 二叉树的顺序存储结构的C++实现
- Python实现二叉树存储结构的堆排序
- 实验六:实现二叉树链式存储结构
- [数据结构][二叉链表]二叉树链式存储结构的二叉链表实现
- 二叉树的存储结构
- 二叉树的存储结构
- 二叉树的存储结构
- 二叉树的存储结构
- 二叉树的存储结构
- 二叉树的存储结构
- 二叉树的存储结构
- 二叉树的存储结构
- J2EE遍历所有request的属性
- Unity3D-- GUI 时钟脚本
- struct 结构体大小的判断
- Linux根目录各个系统文件夹的含义和用途
- USACO Section 1.2 Palindromic Squares
- 二叉树数组存储结构实现
- maven从安装到使用---综合介绍
- Ajax返回状态status明细说明
- 一封邮件的认知
- Java连接oracle数据库实例
- 设计模式之建造者模式
- NULL与MySQL空字符串的区别
- Oracle 9201升级到9208出现乱码报错
- 音频采样