typedef int TElemType;
#define INT
TElemType Nil=8;
#include "treehead.h"
#include "treename.h"
#include "treestruct.h"
const int PLUS=-1;
const int MINUS=-2;
const int ASTERISK=-3;
const int SLANT=-4;
Status visitT(TElemType e)
{
#ifdef CHAR
printf("%c ",e);
#endif
#ifdef INT
printf("%d ",e);
#endif
return OK;
}
double value(BiTree T,float opnd[])
{
float Lv,Rv,v;
if(!T) return 0;
if(T->data>=0) return opnd[T->data];
Lv=value(T->lchild,opnd);
Rv=value(T->rchild,opnd);
switch(T->data)
{
case PLUS:v=Lv+Rv;break;
case MINUS:v=Lv-Rv;break;
case ASTERISK:v=Lv*Rv;break;
case SLANT:v=Lv/Rv;break;
default:ERROR("不合法的运算操作法");
}
return v;
}
int main()
{