第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

寫了一個(gè)二叉搜索樹(shù),搜索函數(shù)返回搜索次數(shù),為什么次數(shù)一直是0,要哭了,求幫忙

寫了一個(gè)二叉搜索樹(shù),搜索函數(shù)返回搜索次數(shù),為什么次數(shù)一直是0,要哭了,求幫忙

C++
慕UI8082421 2016-11-26 23:12:03
//二叉查找樹(shù) #include<iostream> using namespace std; class Node{ public: // int index;//索引 int data; Node *pLchild; Node *pRchild; Node(); void Addnode(int x,Node *&p); int Find(int x,Node *p,int &count); void insubtree(Node*node); }; Node::Node() { data=0; pLchild=NULL; pRchild=NULL; } void Node::Addnode(int x,Node *&p) { if(!p){ p=new Node(); p->data =x; p->pLchild =p->pRchild =NULL; } else{ if(x<p->data ){ Addnode(x,p->pLchild); } else if(x>p->data){ Addnode(x,p->pRchild); } } } int Node::Find(int x,Node *p,int &count){ if(p==NULL) return 0; count+=1; if(x==p->data ) return count; else if(x>p->data ) Find(x,p->pRchild ,count); else if(x<p->data ) Find(x,p->pLchild ,count); } void Node::insubtree(Node*node) { if(node==NULL) return; insubtree(node->pLchild);//先遍歷左子樹(shù) cout<<node->data<<" ";//輸出根節(jié)點(diǎn) insubtree(node->pRchild);//再遍歷右子樹(shù) } class Tree{ public: Tree(int data); ~Tree(); void Addnode(int x); int Find(int x); void insubtree(); private: Node *pRoot; }; Tree::Tree(int data){ pRoot=new Node(); pRoot->data=data; pRoot->pLchild =NULL; pRoot->pRchild =NULL; } void Tree::Addnode(int x){ pRoot->Addnode(x,pRoot); } int Tree::Find(int x) { int count=0; pRoot->Find(x,pRoot,count); } void Tree::insubtree() { pRoot->insubtree(pRoot); } int main(){ int n; cin>>n; Node a[n]; cin>>a[0].data ; Tree *tree=new Tree(a[0].data); //34, 76, 45, 18, 26, 54, 92, 65 for(int i=0;i<n-1;i++){ cin>>a[i+1].data; tree->Addnode(a[i+1].data); } tree->insubtree() ; //int count=0; cout<<tree->Find(76); }
查看完整描述

1 回答

?
onemoo

TA貢獻(xiàn)883條經(jīng)驗(yàn) 獲得超454個(gè)贊

發(fā)帖時(shí)有格式化工具,把代碼格式化好再發(fā)一遍吧,你這一堆東西看得我也快哭了...

查看完整回答
2 反對(duì) 回復(fù) 2016-11-29
  • 1 回答
  • 0 關(guān)注
  • 1226 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)