//
求到某一顶点的路径,倒序
#include<stdio.h>
#include<stdlib.h>
struct Node{
int weight;
Node *left;
Node *right;
};
Node *CreateTree(){
Node *root = NULL;
int ch;
scanf("%d",&ch);
if(ch!=-1){
root = (Node *)malloc(sizeof(Node));
root->weight = ch;
root->left = CreateTree();
root->right = CreateTree();
}
return root;
}
int GetWay(Node *root,int k){
if(root==NULL){
return 0;
}
if(root->weight==k){
printf("%d ",k);
return 1;
}
int l = GetWay(root->left,k);
int r = GetWay(root->right,k);
if(l+r!=0){
printf("%d ",root->weight);
return 1;
}else
{
return 0;
}
}
int main(){
Node *root;
root = CreateTree();
GetWay(root,1);
system("pause");
return 0;
}