注册 登录
编程论坛 C++教室

关于一个错误的指针

yixiliuyun 发布于 2007-06-19 07:34, 446 次点击

#include <iostream>

using namespace std;

//建立结构
typedef struct BSTree
{
int x; //值
struct BSTree *next;
};
BSTree *SearchBST(BSTree *T , BSTree *f)
{
if(T == NULL) return f;
else SearchBST(T->next , T);
}//SearchBST

int main()
{
BSTree *p = NULL , *TH;
TH = (BSTree *)malloc(sizeof(BSTree));
TH->x = 5;
TH->next = NULL;
p = SearchBST(TH , TH);
cout << p;
return 0;
}
cout << p;我感觉输出应该是TH的地址阿
但不知为什么是0
要怎么改正

2 回复
#2
HJin2007-06-19 08:25
SearchBST(T->next , T);

-->

else return SearchBST(T->next , T);

you did not return for the "else" branch.

#3
yixiliuyun2007-06-19 11:38
回复:(HJin)SearchBST(T->next , T); -->els...
谢谢阿  嘿嘿
1