方法一:层次遍历二叉树,并且保存每个节点的父节点位置(头结点可设为0)。从rear到1,遍历就行了。
方法二:采用递归的方法,代码如下:
void AllPath(BTNode *b,char *Ch,int Len) { int i; if (b!=NULL) { if (b->Leftchild==NULL&&b->Rightchild==NULL) { printf("%c\t",b->date); for(i=Len-1;i>=0;i--) printf("%c\t",Ch[i]); } else { Ch[Len]=b->date; Len++; AllPath(b->Leftchild,Ch,Len); AllPath(b->Rightchild,Ch,Len); Len; } } }