資源簡介
在二叉樹類binarytree中增加一個功能,判斷是否為完全二叉樹(使用自定義的隊列類完成)
代碼片段和文件信息
#include
using?namespace?std;
//隊列定義
template
class?flinkQueue
{
private:
????struct?node
????{
????????T?data;
????????node*next;
????????node(const?T&xnode*N=NULL){data=x;next=N;}
????????node():next(NULL){}
????????~node(){}
????};
????node*f;
public:
????flinkQueue(){f=NULL;}
????~flinkQueue()
????{
????????node*t;
????????while(f!=NULL)
????????{
????????????t=f;
????????????f=f->next;
????????????delete?t;
????????}
????}
????bool?isEmpty(){return?f==NULL;}
????void?enq(const?T&x)//插入
????{
????????if(f==NULL)f=new?node(x);
????????else{
????????????node*r=f;
????????????while(r->next!=NULL)r=r->next;
????????????r->next=new?node(x);
????????}
????}
????T?deq()//刪除
????{
????????node*t=f;
????????T?value=f->data;
?
- 上一篇:LR語法分析
- 下一篇:數(shù)據(jù)結(jié)構(gòu)-渡口模擬隊列
評論
共有 條評論