• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

写了一个二叉搜索树,搜索函数返回搜索次数,为什么次数一直是0,要哭了,

//二叉查找树#includeusing 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(xdata ){                        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(xdata ) Find(x,p->pLchild ,count);} void Node::insubtree(Node*node){     if(node==NULL) return;    insubtree(node->pLchild);//先遍历左子树    coutpLchild =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>a[i+1].data;                tree->Addnode(a[i+1].data);        }    tree->insubtree() ;        //int count=0;        cout

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

全部参与1

发帖时有格式化工具,把代码格式化好再发一遍吧,你这一堆东西看得我也快哭了...

使用道具 举报

发新帖

发布任务需求已有1031167位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!