Re: [問題] class

看板Programming作者 (知足常樂)時間18年前 (2007/12/22 11:24), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/3 (看更多)
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)
文章代碼(AID): #17R8Dob2 (Programming)
討論串 (同標題文章)
以下文章回應了本文
1
1
完整討論串 (本文為第 2 之 3 篇):
1
1
1
1
18年前, 12/21
文章代碼(AID): #17R8Dob2 (Programming)