用循环解决小数和多位数问题,未使用atof函数。采用将运算式保存在二维数组的方式进行数据的输入,最后整齐输出。
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<math.h>
//#pragma warning(disable:)
using namespace std;
#define MAXSIZE 1000
typedef struct OPND{
double *base;
double *top;
int stacksize;
}stack1;
typedef struct OPTR {
char *top;
char *base;
int stacksize;
}stack2;
double operate(double a,stack2 &t, double b) {
if (*t.top == '+') {
return a+b;
}
if (*t.top == '-') {
return a-b;
}
if (*t.top == '*') {
return a*b;
}
if (*t.top == '/') {
return a / b;
}
}
void compare(char ch,stack2 &p,stack1&s) {
switch (ch) {
case '+':if (*p.top == '*' || *p.top == '/') {
*(s.top - 2) = operate(*(s.top - 2), p, *(s.top - 1));
*(s.top - 1) = 0;
s.top--;
*p.top &