实验三1.h

来自「希尔排序算法的实现C++sdvzvaGedgvfsewfcAWfqawfaswf」· C头文件 代码 · 共 61 行

H
61
字号
#ifndef BINTREE_H
#define BINTREE_H
#include<iostream.h>
template<class Type> class bintree;
template<class Type> class bintreenode{
	friend class bintree<Type>;
	public:
		bintreenode():leftchild(NULL),righechild(NULL){}
		bintreenode(Type item,bintreenode<Type> *left=NULL,bintreenode<Type> *right=NULL):data(item),leftchild(left),rightchild(right){}
	private:
		bintreenode<Type> *leftchild, *rightchild;
		Type data;
};

template<class Type> class bintree{
	public:
		bintree():root(NULL){}
		bintree(Type value):refvalue(value),root(NULL){}
		void CreateBinTree (bintreenode<Type> * &current);
		int IsEmpty(){return root==NULL?1:0;}
       int size(bintreenode<Type> *t);
		void destroy(bintreenode<Type> *current);
		void inorder(bintreenode<Type> *t);
		bintreenode<Type> *root;
	private:
		Type refvalue;
};
template<class Type> void bintree<Type>::CreateBinTree(bintreenode<Type> * &current){
   Type item;
	//cout<<"顺序输入树结点的值:";
	cin>>item;  
if (item!=00){
	current=new bintreenode<Type>(item);	 
	CreateBinTree(current->leftchild);
	CreateBinTree(current->rightchild);
     }
       else current=NULL;  
}
/*template<class Type>void bintree<Type>::destroy(bintreenode<Type> *current){
	if(current!=NULL){
		destroy(current->leftchild);
		destroy(current->rightchild);
		delete current;
	}
}
*/
template<class Type>int bintree<Type>::size(bintreenode<Type> *t)
{
	if(t==NULL) return 0;
	else return (1+size(t->leftchild)+size(t->rightchild));
}

template<class Type>void bintree<Type>::inorder(bintreenode<Type>* t){

	if(t!=NULL){
		cout<<t->data<<"  ";
		inorder(t->leftchild);
		inorder(t->rightchild);
		}
}
#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?