求助
#include<iostream>
#include<string.h>
using namespace std;
//
template <class T>
class BinaryTreeNode
{
public:
BinaryTreeNode(){LeftChild=RightChild=0;}
BinaryTreeNode(const T& e)
{ data=e;
LeftChild=RightChild=0;
}
BinaryTreeNode(const T& e, BinaryTreeNode * l, BinaryTreeNode *r)
{
data=e;
LeftChild=l;
RightChild=r;
}
T data;
BinaryTreeNode<T> * LeftChild, * RightChild;
};
//
template<class T>
class BinaryTree
{
public:
BinaryTreeNode<T> *root;
BinaryTree(void){
root=NULL;}
~BinaryTree(void){}
bool IsEmpty(void)const
{return ((root)?FALSE:TRUE);}
bool Root(T&x)const;
BinaryTreeNode<T> *MakeTree(const T&element,BinaryTreeNode<T>*left=NULL,BinaryTreeNode<T>*right=NULL);
};
template<class T>
BinaryTreeNode<T> *BinaryTree<T>::MakeTree(const T&element,BinaryTreeNode<T>*left,BinaryTreeNode<T>*right)
{
root=new BinaryTreeNode<T>(element,left,right);
if(root==NULL)
{
cerr<<"Memory allocation failure!\n:";
exit(1);
}
return root;
};
//队列
template<class T>
class Queue
{
private:
int rear, front;
T * elements;
int MaxSize;
public:
Queue(int MaxSize);
~Queue(void){delete [ ] elements;}
int EnQueue(const T& item);
T DeQueue(void);
void MakeEmpty(void){front=rear=0;}
int IsEmpty(void) const {return front==rear;}
int IsFull(void) const{return front==(rear+1)%MaxSize;}
int Length(void) const {return (rear-front+MaxSize)%MaxSize;}
};
template<class T>
Queue<T>::Queue(int s)
{
MaxSize=s;
elements=new T [MaxSize];
front=rear=0;
}
template<class T>
int Queue<T>::EnQueue(const T& item)
{
if(!IsFull())
{
elements[rear]=item;
rear=(rear+1)%MaxSize;
return 0;
}
else return -1;
}
template<class T>
T Queue<T>::DeQueue(void)
{
if(!IsEmpty())
{
T item=elements[front];
front=(front+1)%MaxSize;
return item;
}
else return NULL;
}
//判断完全二叉树
bool is_complete(BinaryTreeNode<int> *root)
{
Queue< BinaryTreeNode <int> > q(100);
BinaryTreeNode *ptr;
q.EnQueue(*root);
while ((ptr = q.DeQueue()) != NULL)
{
q.EnQueue(ptr->left);
q.EnQueue(ptr->right);
}
while (!q.IsEmpty())
{
ptr = q.DeQueue();
if (NULL != ptr)
{
return false;
}
}
return true;
}