1、struct node char *s; type kind; int polar; node *next; node *child; int start;struct step step *child; step *brother; node *lhead; node *rhead; int count; char name30;/初始化,输入表达式int inite(char *s,node *head) int len=strlen(s); int j=0,polar=1; node *current=NULL; node *last=NULL; if(s=NULL)return 0;
2、last=head; while(ilen) if(si=|) if(!(si+1A|si+1kind=or;s=NULL;next=NULL;child=NULL;polar=polar;start=0; if(last-kind=level&last-child=NULL) last-child=current; elsenext=current; last=current; i+; else if(si= current=(node*)malloc(sizeof(node); current-kind=and; if(last- last- else last=current; i+;)
3、return 0; polar=1-polar;- if(si+1!|(si+2!si+2!(si+2|si+2)|i=0)return 0;kind=detrusion; i=i+2; if(si+1!|si+2!)|(si+3!si+3!(si+3|si+3)|i=0)&kind=equal; i=i+3; else if(si|sikind=variable; s=(char*)malloc(MAX_L*sizeof(char); j=0; while(si)|(sis)j=si; j+; if(si!si!0) (current-s)j=; polar=1;|si= s=(char*)
4、malloc(2*sizeof(char);s)0=si;s)1=kind=level; polar=1; if(!inite(s,last)return 0; P return 1; else return 0; return 1;/复制函数node* clone(node *parent) node *son=NULL; if(parent=NULL)return NULL; son=(node*)malloc(sizeof(node); son-kind=parent-kind;polar=parent-polar;s=parent-s;start=parent-start; if(pa
5、rent-next!=NULL) son-next=clone(parent-next); elsechild!child=clone(parent-child); return son;void remove(node *head) current=head; if(current=NULL)return; if(current-current-child-kind=variable&next=NULL) current-polar=(current-polar=current-polar);polar=1; while(current-child=current-child;=NULL)r
6、emove(current-void restruct(node* head) node *newone=NULL,*newtwo=NULL,*newthree=NULL,*newfour=NULL,*newcurrent=NULL; int order=1; while(order while(current! if(current-kind=variable|current-kind=level)&order=1) if(current-=NULL&next-kind=and) newone=(node*)malloc(sizeof(node); newone-polar=0; if(la
7、st-kind=level) last-child=newone; elsenext=newone;next=current-next; current-polar=1-current- current=newone; last=current; current=current- else if(current-order=2)kind=or) newone=(node*)malloc(sizeof(node);order=3)kind=equal) newtwo=(node*)malloc(sizeof(node); newtwo- newthree=(node*)malloc(sizeof
8、(node); newthree- newfour=(node*)malloc(sizeof(node); newfour-child=newtwo; next=newthree;next=newfour; newcurrent=clone(current); newcurrent-child=newcurrent-next=newcurrent-next=newcurrent; else if(current-order=4) restruct(current); current=current- order+;void show(node *head) while(current! if(current- if(current-polar=0)printf();start!=1|(current-polar=0&=NULL)printf( show(current-) current=current-