| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 703 人关注过本帖
标题:求解?做的一个二叉排序树的程序没法运行?
只看楼主 加入收藏
CEO小贼
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-10-24
收藏
 问题点数:0 回复次数:1 
求解?做的一个二叉排序树的程序没法运行?
#include<stdio.h>
#include<stdlib.h>
#define N 10
typedef struct BiTNode{
    int key;
    struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
void CreateBiT(BiTree &T,int data[])
{
    BiTree *current,*father,*p;
    int i;
    for(i=0;i<N;i++)
    {
        p=(BiTree *)malloc(sizeof(BiTNode));
        p->key=data[i];
        p->lchild=p->rchild=NULL;
        if(T==NULL) T=p;
        else
        {
            while(current!=NULL)
            {
                father=current;
                if(current->key>data[i])
                    current=current->lchild;
                else
                    current=current->rchild;
            }
            
            if(father->key>data[i])
                father->lchild=p;
            else
                father->rchild=p;
        }        
    }
}
BiTree SearchBiT(BiTree &T,int key)
{
    BiTree *p,*father;
    p=T;
    int counter=0;
    while(p!=NULL)
    {
        father=p;
        if(p->key==key) return p;
        else
        {
            if(p->key>key)
                p=p->lchild;
            else
                p=p->rchild;   
        }
        counter++;
    }
    printf("查找的次数为%d",counter);
    return father;
}
void InsertBiT(BiTree &p,int key)
{
    BiTree *s;
    s=(BiTree *)malloc(sizeof(BiTNode));
    s->key=key;
    s->lchild=s->rchild=NULL;
   
    if(p->key>key)
        p->lchild=s;
    else
        p->rchild=s;
}
void DeleteBST(BiTree &q)
{
    BiTree *p,*m,*n;
    p=q;
    if(!p->rchild)
    {
        m=p;
        p=p->lchild;
    }
    else if(!p->lchild)
    {
        m=p;
        p=p->rchild;
        
    }
    else
    {
        m=p;n=p->lchild;
        while(n->rchild)
        {
            m=n;n=n->rchild;
        }
        p->key=n->key;
        if(m!=p)
            m->lchild=n->lchild;
        else
            m->lchild=n->lchild;
    }
}
void main()
{
    BiTree *T,*p,*q;
    int i,key,num;
    int data[N];
    printf("请按数字空格的格式依次输入是个整数\n");
    for(i=0;i<=N;i++)
    {scanf("%d",&data[i]);}
    CreateBiT(T,data);
    printf("请输入待查询的整数\n");
    scanf("%d",&key);
    p=SearchBiT(T,key);
    if(p->key==key) printf("您要查找的数据为%d",p->key);
    else
    {InsertBiT(p,key);
    printf("没有找到该数据,已帮您插入到二叉排序树\n");
    }
    printf("请输入待删除的数据\n");
    scanf("%d",&num);
    q=SearchBiT(T,num);
    if(q->key==num) DeleteBiT(q);
    else
        printf("您输入的数据有误");
}

搜索更多相关主题的帖子: current include father 
2013-11-28 16:22
CEO小贼
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-10-24
收藏
得分:0 
--------------------Configuration: 3 - Win32 Debug--------------------
Compiling...
3.cpp
E:\3\3.cpp(15) : error C2227: left of '->key' must point to class/struct/union
E:\3\3.cpp(16) : error C2227: left of '->lchild' must point to class/struct/union
E:\3\3.cpp(16) : error C2227: left of '->rchild' must point to class/struct/union
E:\3\3.cpp(17) : error C2440: '=' : cannot convert from 'struct BiTNode ** ' to 'struct BiTNode *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
E:\3\3.cpp(23) : error C2227: left of '->key' must point to class/struct/union
E:\3\3.cpp(24) : error C2227: left of '->lchild' must point to class/struct/union
E:\3\3.cpp(26) : error C2227: left of '->rchild' must point to class/struct/union
E:\3\3.cpp(29) : error C2227: left of '->key' must point to class/struct/union
E:\3\3.cpp(30) : error C2227: left of '->lchild' must point to class/struct/union
E:\3\3.cpp(32) : error C2227: left of '->rchild' must point to class/struct/union
E:\3\3.cpp(39) : error C2440: '=' : cannot convert from 'struct BiTNode *' to 'struct BiTNode ** '
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
E:\3\3.cpp(44) : error C2227: left of '->key' must point to class/struct/union
E:\3\3.cpp(44) : error C2440: 'return' : cannot convert from 'struct BiTNode ** ' to 'struct BiTNode *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
E:\3\3.cpp(47) : error C2227: left of '->key' must point to class/struct/union
E:\3\3.cpp(48) : error C2227: left of '->lchild' must point to class/struct/union
E:\3\3.cpp(50) : error C2227: left of '->rchild' must point to class/struct/union
E:\3\3.cpp(55) : error C2440: 'return' : cannot convert from 'struct BiTNode ** ' to 'struct BiTNode *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
E:\3\3.cpp(61) : error C2227: left of '->key' must point to class/struct/union
E:\3\3.cpp(62) : error C2227: left of '->lchild' must point to class/struct/union
E:\3\3.cpp(62) : error C2227: left of '->rchild' must point to class/struct/union
E:\3\3.cpp(65) : error C2440: '=' : cannot convert from 'struct BiTNode ** ' to 'struct BiTNode *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
E:\3\3.cpp(67) : error C2440: '=' : cannot convert from 'struct BiTNode ** ' to 'struct BiTNode *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
E:\3\3.cpp(72) : error C2440: '=' : cannot convert from 'struct BiTNode *' to 'struct BiTNode ** '
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
E:\3\3.cpp(73) : error C2227: left of '->rchild' must point to class/struct/union
E:\3\3.cpp(76) : error C2227: left of '->lchild' must point to class/struct/union
E:\3\3.cpp(78) : error C2227: left of '->lchild' must point to class/struct/union
E:\3\3.cpp(81) : error C2227: left of '->rchild' must point to class/struct/union
E:\3\3.cpp(86) : error C2227: left of '->lchild' must point to class/struct/union
E:\3\3.cpp(87) : error C2227: left of '->rchild' must point to class/struct/union
E:\3\3.cpp(87) : fatal error C1903: unable to recover from previous error(s); stopping compilation
执行 cl.exe 时出错.

3.obj - 1 error(s), 0 warning(s)
这些错误什么意思?
2013-11-28 16:22
快速回复:求解?做的一个二叉排序树的程序没法运行?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016911 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved