#include<stdio.h>
#include<stdlib.h>
typedef struct bin_tree_t
{
struct bin_tree_t *parent;
struct bin_tree_t *left;
struct bin_tree_t *right;
struct bin_tree_t *first;
struct bin_tree_t *next;
unsigned int val;
}intTree;
intTree *createIntTree(intTree *left,intTree *right,unsigned int token)
{
intTree *pt;
pt=(intTree *)malloc(sizeof(intTree));
if(__builtin_expect(pt==NULL,0))
{
return NULL;
}
pt->val=token;
pt->next=NULL;
pt->first=NULL;
pt->parent=NULL;
pt->left=left;
pt->right=right;
if(left!=NULL)
left->parent=pt;
if(right!=NULL)
right->parent=pt;
return pt;
}
int main(void)
{
intTree *t1;
intTree *t2;
intTree *p;
intTree *root;
int loop;
t1=createIntTree(NULL,NULL,1);
t2=t1;
for(loop=2;loop<10;loop++)
{
p=createIntTree(t1,NULL,loop);
t1=p;
}
//root=p;
//visit tree from Top->bottom
while(p)
{
printf("p->val=%d\n",p->val);
p=p->left;
}
printf("###########################################\n");
//Visit tree from bottom to top
p=t2;
while(p)
{
printf("p->val=%d\n",p->val);
p=p->parent;
}
}
作用非常像一个双向链表