#include
#include
#include
#define true 1
#define flase 0
#define ok 1
#define error 0
#define overflow -1
#define stack_size 100
#define stackincrement 10
typedef int status;
typedef float selemtype;
typedef struct snodesqstack;
status initstack(sqstack &s)
status gettop(sqstack s,selemtype &e)
status push(sqstack &s,selemtype e)
*s.top++=e;
return ok;
}status pop(sqstack &s,selemtype &e)
bool in(char c)
int locatechar(char c)
return k;
}char precede(char c1, char c2),,
,,,,
};i=locatechar(c1);
j=locatechar(c2);
if(p[i][j]=='$')
exit(-1);
//return p[i][j];
}selemtype operate(selemtype a,selemtype ch,selemtype b)
}selemtype evaluateexpression()
//switch
}//if
else if(c>='0'&&c<='9'||c=='.')
data[i]='\0';//數字沒有存滿,輸入字串結束符
d=atof(data);//此處是把陣列裡的數字,實際上是按字串;轉換為double型別,然後把浮點型數字入棧
push(opnd,d);//atof函式的形參是指標型別,故用陣列名
}else
gettop(optr,e);
}gettop(opnd,e);
return e;
}int main()
{selemtype a;
printf("please input the expression ,and end in'#':\n");
a=evaluateexpression();
printf("%f\n",a);
return 0;
//------------------自己真是太粗心了,寫函式時,有時候會忘記寫分號,忘了函式值返回值
棧應用 表示式求值
include stdafx.h include using namespace std const int explenght 20 const int stack init size 20 const int stack incrment 10 templateclass stack stack...
棧應用 表示式求值
include include define length 100 初始分配棧的長度 define add len 10 棧長增量 typedef struct 定義字元棧 sqstack void initstack sqstack s 初始化乙個棧 void push sqstack s,int...
表示式求值 棧的應用
表示式求值 西西設計的機械人卡多掌握了加減法運算以後,最近又學會了一些簡單的函式求值,比如,它 知道函式min 20,23 的值是20 add 10,98 的值是108等等。經過訓練,西西設計的機械人卡多 甚至會計算一種巢狀的更複雜的表示式。假設表示式可以簡單定義為 1.乙個正的十進位制數 x 是乙...