struct Part *create() { structPart *phead=0,*ptemp=0,*ptail=0; double num;char sign; printf("****Welcome to magic caculator!****\n"); printf("Input:"); scanf("%lf%c",&num,&sign); while (1){ ptemp=(struct Part *)malloc(sizeof(struct Part)); ptemp->num=num; ptemp->sign=sign; ptemp->Pnext=0; if (!phead) phead=ptail=ptemp; else { ptail->Pnext=ptemp; ptail=ptemp; } if (sign=='='||sign=='\n') break; scanf("%lf%c",&num,&sign); } return phead; }
struct Part *transfer(struct Part *phead) { structPart *phead1;structPart *p; phead1=phead; if (phead->sign=='*'){ (phead->Pnext)->num=phead->num*(phead->Pnext)->num; phead->num=0; phead->sign='+';} if (phead->sign=='/'){ (phead->Pnext)->num=phead->num/(phead->Pnext)->num; phead->num=0; phead->sign='+';} p=phead; phead=phead->Pnext; while (phead->sign!='='&&phead->sign!='\n'){ if (phead->sign=='*'){ (phead->Pnext)->num=phead->num*(phead->Pnext)->num; phead->num=0; if (p->sign=='+') phead->sign='+'; else phead->sign='-'; }
if (phead->sign=='/'){ (phead->Pnext)->num=phead->num/(phead->Pnext)->num; phead->num=0; if (p->sign=='+') phead->sign='+'; else phead->sign='-'; } p=phead; phead=phead->Pnext; } return phead1; }
doublecaculate(struct Part *phead) { double sum=phead->num; while (phead->sign!='\n'&&phead->sign!='='){ if(phead->sign=='-') sum=sum-(phead->Pnext)->num; if(phead->sign=='+') sum=sum+(phead->Pnext)->num; phead=phead->Pnext; } return sum; }