2024年5月4日发(作者:)
表达式求值,可直接复制到VC中运行。
#include
#include
#include
#include
static int gv_a;
typedef struct list //创建队列元素型
{
char str[10];
struct list*pNext;
}LIST;
typedef struct queue
{
LIST *front;
LIST *rear;
}QUEUE;
//创建队列表型
typedef struct oprstack
{
char opr[100];
int a;
}OPRSTACK;
typedef struct valstack
{
float val[30];
int a;
}VALSTACK;
//创建运算符栈型
//创建运算栈型
typedef struct element //创建表达式栈元素型
{
char c;
struct element *pNext;
}ENT;
typedef struct stack //创建表达式栈 型
{
ENT *pTop;
ENT *bottom;
}STACK;
bool calc(char *str,float *result);
float evaluationofexpression(char *str);
int main(void)
{
char str[50];
float result;
printf("请输入要计算的表达式:");
scanf("%s",str);
result = evaluationofexpression(str);
if (gv_a)
return 0;
printf("结果:%f",result);
printf("n");
return 0;
}
/*=======================================================*/
/*==================不带括号表达式求值===================*/
/*=======================================================*/
void insert_char(char *p,char ent,int site)
{
int i=0,j;
while (p[i]!='0')
++i;
if(site>i)
{
p[i] = ent;
p[i+1] = '0';
return;
}
for (j=i;j>=site;--j)
{
p[j+1] = p[j];
}
p[site] = ent;
}
//向字符串中插入一个元素
发布者:admin,转转请注明出处:http://www.yc00.com/web/1714816200a2521525.html
评论列表(0条)