2011-12-21 166 views
0

可能重复:
C : pointer to struct in the struct definitionC结构,指针

在我beginer当然,我们需要声明的树搜索一个结构。我需要在每个节点中引用相同类型的指针。这种删节看起来不正确,在这种情况下,pnode是不知道的。我怎样才能实现我的目标?

typedef struct 
{ 
    int value; 
    int right; 
    int left; 
    pnode nextleft; 
    pnode nextright; 
}node, *pnode; 

回答

1
struct node 
{ 
    int value; 
    int right; 
    int left; 
    struct node *nextleft; 
    struct node *nextright; 
}; 

这里,node标签命名空间内。

+0

+1之前使用的typedef如果你想避免使用'结构node'和'结构节点*'申报情况你的结构仍然可以添加'typedef struct node node; typedef struct node * pnode;'在结构定义之后。尽管为了代码清晰,我宁愿不要。 – JoeFish 2011-12-21 20:24:29