Re: [問題] class
node* tree::findNode(element key)
{
node *p = root;
p=find(p,key);
count=0;
return p;
}
static int count=0; node *q=0;
node* tree::find(node *p,element key)
{
if(p!=0)
{
if(p->left!=0&&p->right!=0)
{
q=p;
find(p->left, key);
}
if(strcmp(p->data,key)==0)
{
count++;
}
else{
if((count==1)&&(strcmp(q->left->data,key)==0))
{
return q->left;
}
else
{
if(p->left!=0&&p->right!=0)
find(p->right, key);
}
}
if(count==1){
return q->right;
}
}
}
void tree::traverse(int order)
{
if (order == PRE_ORDER)
preorder(root, 0);
else if (order == IN_ORDER)
inorder(root, 0);
else if (order == POST_ORDER)
postorder(root, 0);
else if(order ==STRING_PREORDER)
string_preorder(root);
else
cout << "no such order " << endl;
}
void tree::inorder(node *p, int level)
{
if (p != 0)
{
inorder(p->left, level+1);
cout << "Node " << p->data << " at level " << level << endl;
inorder(p->right, level+1);
}
}
※ 編輯: ntouckcm 來自: 140.121.219.142 (12/22 11:27)
討論串 (同標題文章)
Programming 近期熱門文章
PTT數位生活區 即時熱門文章