考虑到 出现相同的数等等
#include#include int cache[1001];int read=0,n;struct node*root;struct node{ int value; struct node* father; struct node* lchild; struct node* rchild;};void BuildTree(struct node*&Node,struct node*father){ Node=(struct node*)malloc(sizeof(struct node)); Node->lchild=Node->rchild=NULL; if(read==0) Node->father=NULL; //头节点 else Node->father=father; Node->value=cache[read++]; while(read father&&Node->father->lchild==Node&&cache[read]>Node->father->value)// break; if(Node->father&&Node->father->rchild==Node&&cache[read] father->value) break;*/ father=Node;//不好的习惯 一个变量两用 father改变用法了 while(father->father){//??? if(father->father->lchild==father&&cache[read] father->value) father=father->father; else if(father->father->rchild==father&&cache[read]>=father->father->value) father=father->father; else return ; } if(cache[read] value) BuildTree(Node->lchild,Node); else BuildTree(Node->rchild,Node); }}void postorder1(struct node*Node){ if(Node==NULL) return; postorder1(Node->lchild); postorder1(Node->rchild); if(read==n) read=0; else printf(" "); printf("%d",Node->value); };void postorder2(struct node*Node){ if(Node==NULL) return; postorder2(Node->lchild); postorder2(Node->rchild); if(root!=Node) printf(" "); printf("%d",-Node->value);};int main(){ int mirror=1; scanf("%d",&n); for(int i=0;i