| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 526 人关注过本帖
标题:没分了,但问题还在,得解决,亲们,拜托了,关于结构体指针的
只看楼主 加入收藏
icanbestrong
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:100
专家分:138
注 册:2013-3-13
结帖率:50%
收藏
 问题点数:0 回复次数:7 
没分了,但问题还在,得解决,亲们,拜托了,关于结构体指针的
#include "stdio.h"
#define MAX 20
typedef struct LNode
{
int data;
LNode *right;
LNode *left;
}LNode;
typedef struct title
{
int length;
LNode *head;
}title;
void bijiao(LNode n,LNode* first){
    if(n.data>first.data){
    if(first.right=NULL)
       first.right=&n;
    else bijiao(n,first.right);//有问题 cannot convert parameter 2 from 'struct LNode *' to 'struct LNode'
    }
    else {
    if(first.left=NULL)
       first.left=&n;
    else bijiao(n,first.left);//有问题 cannot convert parameter 2 from 'struct LNode *' to 'struct LNode'
    }
}
int main(){
int n;
title tit;
LNode lno[MAX];
printf("please input the length(0<n<=20:");
scanf("%d",&n);
tit.length=n;
printf("\nplease input the values");
for(n=0;n<tit.length;n++)
scanf("%d",lno[n].data);
tit.head=lno;//表头获得根的地址
for(n=0;n<tit.length;n++)
lno[n].left=lno[n].right=NULL;//初始化结点的左右子节点
for (n=1;n<tit.length;n++)
bijiao(lno[0],lno[n]);//创建树
return 0;
}
还有,我这样定义的这个bijiao函数不会修改lno[Max]中结点左右子节点的值啊,是不是还是NULL,大神们,嘿嘿
搜索更多相关主题的帖子: convert include cannot 结构体 title 
2013-12-08 16:26
icanbestrong
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:100
专家分:138
注 册:2013-3-13
收藏
得分:0 
对了,亲们,我会追加分的,正在努力得分。。。
2013-12-08 16:37
li_local
Rank: 2
等 级:论坛游民
帖 子:35
专家分:59
注 册:2013-11-21
收藏
得分:0 
else bijiao(n,first.right);//有问题 cannot convert parameter 2 from 'struct LNode *' to 'struct LNode' ----first是个指针!first->right
另外 函数形参为什么要搞成结构体变量类型? 最好改成结构体指针类型的
2013-12-08 18:48
icanbestrong
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:100
专家分:138
注 册:2013-3-13
收藏
得分:0 
可是这样也不行啊,我试了
2013-12-08 21:28
zhaogay
Rank: 7Rank: 7Rank: 7
来 自:宫
等 级:黑侠
帖 子:151
专家分:586
注 册:2013-10-10
收藏
得分:0 
#include "stdio.h"
 #define MAX 20
 typedef struct LNode
 {
 int data;
 struct LNode *right;
 struct LNode *left;
 }LNode;
 typedef struct title
 {
 int length;
 LNode *head;
 }title;
 void bijiao(LNode n,LNode* first){
     if(n.data>first->data){
     if(first->right=NULL)
        first->right=&n;
     else bijiao(n,first->right);//有问题 cannot convert parameter 2 from 'struct LNode *' to 'struct LNode'
     }
     else {
     if(first->left=NULL)
        first->left=&n;
     else bijiao(n,first->left);//有问题 cannot convert parameter 2 from 'struct LNode *' to 'struct LNode'
     }
 }
 int main(){
 int n;
 title tit;
 LNode lno[MAX];
 printf("please input the length(0<n<=20:");
 scanf("%d",&n);
 tit.length=n;
 printf("\nplease input the values");
 for(n=0;n<tit.length;n++)
 scanf("%d",lno[n].data);
 tit.head=lno;//表头获得根的地址
for(n=0;n<tit.length;n++)
 lno[n].left=lno[n].right=NULL;//初始化结点的左右子节点
for (n=1;n<tit.length;n++)
 bijiao(lno[0],&lno[n]);//创建树
return 0;
 }
编译能过

好好学习,天天想上
2013-12-09 01:00
icanbestrong
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:100
专家分:138
注 册:2013-3-13
收藏
得分:0 
我跟你改的差不多,可是我用vc编译了一下,过不去,而用dev c++编译了时,是能过去,但运行一下就又出错了
2013-12-09 13:35
icanbestrong
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:100
专家分:138
注 册:2013-3-13
收藏
得分:0 
#include "stdio.h"
#define MAX 20
typedef struct LNode
{
int data;
struct LNode *right;
struct LNode *left;
}LNode;
typedef struct title
{
int length;
LNode *head;
}title;
void diaoyong(int n,LNode lno){
LNode *p;
if(n==lno.data) printf("找到了!");
else {
if(n>lno.data)
{if(lno.right!=NULL)
{p=lno.right;
diaoyong(n,*p);
}
else printf("不存在!");}
else
{if(lno.left!=NULL)
{p=lno.left;
diaoyong(n,*p);}
else printf("不存在!");}
}
}
void bijiao(LNode n,LNode* first){
     if(n.data>first->data){
     if(first->right=NULL)
        first->right=&n;
     else bijiao(n,first->right);//有问题 cannot convert parameter 2 from 'struct LNode *' to 'struct LNode'
     }
     else {
     if(first->left=NULL)
        first->left=&n;
     else bijiao(n,first->left);//有问题 cannot convert parameter 2 from 'struct LNode *' to 'struct LNode'
     }
}
int main(){
int n;
title tit;
LNode lno[MAX];
int a[MAX]={12,34,56,67,86,13,-1};
n=0;
while(a[n]!=-1){
n++;}
tit.length=n;
tit.head=lno;//表头获得根的地址
for(n=0;n<tit.length;n++)
lno[n].left=lno[n].right=NULL;//初始化结点的左右子节点
for (n=1;n<tit.length;n++)
bijiao(lno[0],&lno[n]);//创建树
printf("please input the value:");
scanf("%d",&n);
diaoyong(n,lno[0]);
return 0;
}
我把我所有的代码全贴出来了,代码功能是递归建立一个二叉排序树,并查找输入元素是否在表内,可惜就是指针表示这块有错误,vc编译不过去,dev编译过去了,但运行不出结果来,望哪位好心的大神帮帮我,也许某天你也会需要我这一小菜鸟的帮助呢,谢谢了
2013-12-09 13:55
icanbestrong
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:100
专家分:138
注 册:2013-3-13
收藏
得分:0 
#include<stdio.h>
#include<malloc.h>
#define Max 10
int Data[Max]={15,2,13,6,17,25,7,3,18};//数据数组
int Counter;//计数器
struct Tree{
int Key;//数据变量
struct Tree *Left;//左子树指针
struct Tree *Right;//右子树指针
};
typedef struct Tree TreeNode;
typedef TreeNode *BTree;
BTree Root=NULL;//根部父节点
//建立二叉树
void Create_Tree(int *Data){
BTree New;//新指针变量
BTree Current;//目前指针
BTree Father;//父节点指针
int i;
for(i=0;i<Max;i++){
New=(BTree)malloc(sizeof(TreeNode));//内存配置
New->Key=Data[i];//新指针为输入的指针
New->Left=NULL;//左子树结点
New->Right=NULL;//右子树结点
if(Root==NULL)//当前节点连接任何子树时
Root=New;//根节点为新结点
else{
Current=Root;//目前的位置在根节点
while(Current!=NULL)//当前的结点为最低端则结束循环
{Father=Current;//记录父节点
if(Current->Key>=Data[i])
Current=Current->Left;//往左子树
else
Current=Current->Right;//往右子树
}
if(Father->Key>Data[i])//串起父与子节点
Father->Left=New;
else
Father->Right=New;
}
}
}
//查找二叉树
int Tree_Search(int Key){
BTree Pointer;
Pointer=Root;
Counter=0;
while(Pointer!=NULL){
Counter++;
//查找结点数据小于欲查找数据
if(Pointer->Key<Key)
Pointer=Pointer->Right;//往左子树
//查找结点数据大于欲查找数据
else if(Pointer->Key>Key)
Pointer=Pointer->Left;//往右子树
//查找结点数据等于欲查找数据
else if(Pointer->Key==Key)
return 1;//找到了
}
return 0;//没找到
}
void main(){
int KeyValue;
int i;
printf("Input Data:");
for(i=0;i<Max;i++)
printf("[%d]",Data[i]);
printf("\n");
Root=NULL;
Create_Tree(Data);
while(KeyValue!=-1)//输入-1结束程序
{printf("Please input your key value:");
scanf("%d",&KeyValue);
if(Tree_Search(KeyValue))
printf("Search Time=%d\n",Counter);
else
printf("No Found!\n");
}
}
这是我千辛万苦从我们学校图书馆查到的,贴出来大家共享一下,也许有一天你会用到。和我自己设计的比较了一下,发现该经典算法条例比较清晰,我是先设置了个结构体数组,再在数组的right和left重指向,但就是指针这块出了问题,而该算法指针部分自我感觉设计的很奇妙。总算告一段落了,但如果哪位大神能告诉我的哪里出错了就更好了,小弟必将所有分倾囊相送,虽然一点点,更或能给小弟推荐一本比较好的只关于指针的书,谢谢了
2013-12-09 19:46
快速回复:没分了,但问题还在,得解决,亲们,拜托了,关于结构体指针的
数据加载中...
 
   



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

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