重慶分公司,新征程啟航
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊、服務(wù)器等服務(wù)
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊、服務(wù)器等服務(wù)
構(gòu)建樹:
typedef struct Node
{int data;
Node *lchild;
Node *rchild;
}Node;
class Tree
{ public:
Node *root;
Tree(int data);
Node *maketree(Node *father,int data,int side);
};
Tree::Tree(int data)
{Node *newnode=new Node;
root=newnode;
root->data=data;
root->lchild=NULL;
root->rchild=NULL;
}
Node *Tree::maketree(Node *father,int data,int side)
{Node *newnode=new Node;
newnode->data=data;
newnode->lchild=NULL;
newnode->rchild=NULL;
if(side==0)
{father->lchild=newnode;
}
else
{father->rchild=newnode;
}
return newnode;
}
前序遍歷:
void front_display(Node *start)
{cout<data<<' ';
if(start->lchild)
{front_display(start->lchild);
}
if(start->rchild)
{front_display(start->rchild);
}
}
中序遍歷:
void middle_display(Node *start)
{ if(start->lchild)
{middle_display(start->lchild);
}
cout<data<<' ';
if(start->rchild)
{middle_display(start->rchild);
}
}
后序遍歷:
void last_display(Node *start)
{if(start->lchild)
{last_display(start->lchild);
}
if(start->rchild)
{last_display(start->rchild);
}
cout<data<<' ';
}
未經(jīng)允許,不得轉(zhuǎn)載!
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧