求助
#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;
}
#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;
}
...全文
相关推荐
大学生心理求助态度与心理求助行为的关系研究.docx
【大学生心理求助态度与心理求助行为的关系研究】这篇研究报告探讨了大学生在面对心理困扰时,其心理求助态度与实际求助行为之间的联系。
网络游戏-基于lora网络的求助杆及求助系统.zip
**求助系统设计**:详述求助系统的架构,包括硬件(如求助杆)、软件(信号处理和传输)、用户界面和后台管理系统等组成部分。5.
基于ZigBee技术的门铃及老人求助系统
《基于ZigBee技术的智能门铃及老人求助系统》随着科技的进步,智能家居产品逐渐进入人们的生活,其中,基于ZigBee技术的门铃及老人求助系统以其人性化的功能设计,解决了传统门铃及老人求助的局限性。
校园应急管理数字求助对讲系统.doc
二、对讲求助点的分布1.2.1 校园对讲求助:对讲求助点应覆盖校园的主要区域,如教学楼、图书馆、宿舍区、操场、食堂等人员密集场所。这些地点设置的求助按钮应易于识别和操作,确保在紧急情况下能被迅速触发。
通信与网络中的地铁站内无线乘客求助系统设计方案
"通信与网络中的地铁站内无线乘客求助系统设计方案"地铁站内无线乘客求助系统是现代城市交通中不可或缺的一部分,它旨在提供快速、可靠的乘客求助服务,同时简化安装和维护过程。针对这一需求,设计了一种基于


模式及实现
