一、中缀表达式转后缀表达式并计算,后缀表达式字符串形式,数字限定小于10,利用数字栈操作符栈

 /*  c语言的中缀表达式转后缀表达式并计算结果
中缀表达式含双目运算符和小括号,数字操作数小于10,
演示转变及计算过程
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h> /* 操作符栈结构体 */
typedef struct{
char data[];
int top;
}stack; /* 数字栈结构体 */
typedef struct{
int data[];
int top;
}nstack; /* 栈操作函数声明 */
int priority(char);
char pop(stack*);
int npop(nstack*);
int ntop(nstack*);
char top(stack*);
void push(stack*,char);
void npush(nstack*,char);
bool isnumber(char);
bool isempty(stack*); int main()
{
int i,j,len,cnt;//字符串下标、长度变量 stack *st=(stack*)malloc(sizeof(stack)); //操作符栈
nstack *nst=(nstack*)malloc(sizeof(nstack));//数字栈
st->top=-; //操作符栈空
nst->top=-; //数字栈空 char str[];//中缀表达式字符串
char out[];//后缀表达式字符串 scanf("%s",str);//读取中缀表达式字符串 cnt=;//后缀表达式字符串下标
len=strlen(str);//读取的中缀表达式字符串长度 /* 1.中缀表达式转后缀表达式 */ //1*(2+3)-4
for(i=;i<len;i++)
{
/* 从字符串读取的字符为数字,插入到后缀表达式字符串 */
if(isnumber(str[i]))
out[cnt++]=str[i];
else
{
/* 读取的非数字字符是左括号 或者 操作符栈为空,
读取的字符压到操作符栈,
然后去判断字符串是否读完 */
if(str[i]=='('||isempty(st))
{
push(st,str[i]);
continue;
}
/* 读取的非数字字符是右括号,判断操作符栈是否为左括号,
不是左括号把栈顶的操作符插入到后缀表达式字符串并弹出
最后把左括号弹出,然后去判断字符串是否读完*/
if(str[i]==')')
{
while(top(st)!='(')
{
out[cnt++]=top(st);
pop(st);
}
pop(st);
continue;
}
/* 操作符栈不空且栈顶元素不是左括号
且栈顶元素的优先级大于等于读取的字符优先级
栈顶的操作符插入到后缀表达式字符串并弹出*/
while(!isempty(st)&&top(st)!='('&& priority(str[i])<=priority(top(st)))
{
out[cnt++]=top(st);
pop(st);
}
/* 操作符栈空了或栈顶元素为左括号或
栈顶元素的优先级小于读取的字符优先级
读取的字符压到操作符栈 */
push(st,str[i]);
}
}
/* 操作数栈不为空依次弹出插入到后缀表达式字符串 */
while(!isempty(st)){
out[cnt++]=top(st);
pop(st);
}
out[cnt]='\0';
/* 打印后缀表达式 */ //1 2 3 + * 4 -
for(i=;i<cnt;++i)
printf("%c ",out[i]);
printf("\n"); /* 2.根据后缀表达式计算 */
for(i=;i<cnt;i++)
{
/* 从后缀表示字符串读字符,是数字压数字栈,
然后判断字符串是否读完 */
if(isnumber(out[i])){
npush(nst,out[i]);
continue;
}else if(out[i]=='+'){//数字栈顶元素加到下面元素并弹出栈顶元素
nst->data[nst->top-]+=ntop(nst);
npop(nst);
}else if(out[i]=='-'){//同理减到下面元素
nst->data[nst->top-]-=ntop(nst);
npop(nst);
}else if(out[i]=='*'){ //同理乘到下面元素并弹出栈顶元素
nst->data[nst->top-]*=ntop(nst);
npop(nst);
}else if(out[i]=='/'){ //同理除到下面元素并弹出栈顶元素
nst->data[nst->top-]/=ntop(nst);
npop(nst);
}else if(out[i]=='^'){//同理幂到下面元素并弹出栈顶元素
nst->data[nst->top-]=pow(nst->data[nst->top-],ntop(nst));
npop(nst);
}
for(j=;j<=nst->top;++j)//一趟后剩余的数字栈遍历打印
printf("%d ",nst->data[j]);
for(j=i+;j<cnt;++j) //一趟后剩余的后缀表达式字符打印
printf("%c ",out[j]);
printf("\n");
}
return ;
}
/* 是否数字函数 */
bool isnumber(char ch){
if(ch>=''&&ch<='')
return true;
else
return false;
}
/* 是否栈空函数 */
bool isempty(stack *s){
if(s->top==-)
return true;
else
return false;
}
/* 压栈函数 */
void push(stack *s,char ch){
s->data[++s->top]=ch;
}
void npush(nstack *s,char ch){
s->data[++s->top]=ch-'';
}
/* 弹栈函数 */
char pop(stack *s){
return s->data[s->top--];
}
int npop(nstack *s){
return s->data[s->top--];
}
/* 操作符优先级函数 */
int priority(char ch){
if(ch=='(')
return ;
if(ch=='+'||ch=='-')
return ;
if(ch=='*'||ch=='/')
return ;
if(ch=='^')
return ;
return ;
}
/* 取栈顶元素函数 */
char top(stack *s){
return s->data[s->top];
}
int ntop(nstack *s){
return s->data[s->top];
}

字符串形式

  二、中缀表达式转后缀表达式并计算,后缀表达式结构体数组形式,数字可多位,利用数字栈操作符栈

后缀表达式结构体数组中的联合体既可以存放int类型的数字也可以存放char型操作符,可以判断数组元素的数据类型

 /*  c语言的中缀表达式转后缀表达式并计算结果
中缀表达式含双目运算符和小括号,数字操作数可以多位,
演示转变及计算过程
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h> /* 操作符栈结构体 */
typedef struct{
char data[];
int top;
}stack; /* 数字栈结构体 */
typedef struct{
int data[];
int top;
}nstack; /* 表达式结构体 */
typedef struct {
short b;//判断类型
union {
int num;
char ch;
}u;
}EXPRESSION; /* 栈操作函数声明 */
int priority(char);
char pop(stack*);
int npop(nstack*);
int ntop(nstack*);
char top(stack*);
void push(stack*,char);
void npush(nstack*,int);//参数int
bool isnumber(char);
bool isempty(stack*); int main()
{
int i,j,len,cnt;//字符串下标、长度变量 stack *st=(stack*)malloc(sizeof(stack)); //操作符栈
nstack *nst=(nstack*)malloc(sizeof(nstack));//数字栈
st->top=-; //操作符栈空
nst->top=-; //数字栈空 char str[];//中缀表达式字符串
EXPRESSION out[];//后缀表达式结构体数组
cnt=;//后缀表达式数组下标
int sum = ;//累加数字 scanf("%s",str);//读取中缀表达式字符串
len=strlen(str);//读取的中缀表达式字符串长度
int flag = ;//是数字标识 /* 1.中缀表达式转后缀表达式(用操作符栈) */
for(i=;i<=len;i++)// 100*(2+3)-4 100 2 3 + * 4 -
{
/* 从字符串读取的字符为数字,插入到后缀表达式结构体数组 */
if(isnumber(str[i])&&i<=len){
sum = sum* + str[i] - '';//累加数字
flag = ;//是数字标识
continue;
}
/* 数字进后缀表达式结构体数组的数字 */
if(flag)
{
out[cnt].b = ;
out[cnt++].u.num = sum;
flag = ;
sum = ;
}
/* 读取的非数字字符是左括号 或者 操作符栈为空,
读取的字符压到操作符栈,
然后去判断字符串是否读完 */
if(str[i]=='('||isempty(st))
{
push(st,str[i]);
continue;
}
/* 读取的非数字字符是右括号,判断操作符栈是否为左括号,
不是左括号把栈顶的操作符插入到后缀表达式数组并弹出
最后把左括号弹出,然后去判断字符串是否读完*/
if(str[i]==')')
{
while(top(st)!='(')
{
out[cnt].b = ;
out[cnt].u.ch=top(st); //操作符进后缀表达式数组的字符
cnt++;
pop(st);
}
pop(st);
continue;
}
/* 操作符栈不空且栈顶元素不是左括号
且栈顶元素的优先级大于等于读取的字符优先级
栈顶的操作符插入到后缀表达式数组并弹出*/
while(!isempty(st)&&top(st)!='('&& priority(str[i])<=priority(top(st)))
{
out[cnt].b = ;
out[cnt++].u.ch = top(st);//操作符进后缀表达式数组的字符
pop(st);
}
/* 操作符栈空了或栈顶元素为左括号或
栈顶元素的优先级小于读取的字符优先级
读取的字符压到操作符栈 */
push(st,str[i]);
}
/* 操作符栈不为空依次弹出插入到后缀表达式数组*/
while(!isempty(st)){
out[cnt].b = ;
out[cnt++].u.ch = top(st);//操作符进后缀表达式数组的字符
pop(st);
}
/* 打印后缀表达式 */ //100 2 3 + * 4 - 100*(2+3)-4
for(i=;i<cnt;++i)
{
if(out[i].b==)
printf("%d ",out[i].u.num);
else printf("%c ",out[i].u.ch);
}
printf("\n"); /* 2.根据后缀表达式计算(用操作符栈\数字栈) */
for(i=;i<cnt;i++)
{
/* 从后缀表达式结构体数组读取,是数字压数字栈,
然后判断结构体数组是否读完 */
if(out[i].b == ){
npush(nst,out[i].u.num);
continue;
}
else if(out[i].u.ch=='+'){//数字栈顶元素加到下面元素并弹出栈顶元素
nst->data[nst->top-]+=ntop(nst);
npop(nst);
}else if(out[i].u.ch=='-'){//同理减到下面元素并弹出栈顶元素
nst->data[nst->top-]-=ntop(nst);
npop(nst);
}else if(out[i].u.ch=='*'){ //同理乘到下面元素并弹出栈顶元素
nst->data[nst->top-]*=ntop(nst);
npop(nst);
}else if(out[i].u.ch=='/'){ //同理除到下面元素并弹出栈顶元素
nst->data[nst->top-]/=ntop(nst);
npop(nst);
}else if(out[i].u.ch=='^'){//同理幂到下面元素并弹出栈顶元素
nst->data[nst->top-]=pow(nst->data[nst->top-],ntop(nst));
npop(nst);
} for(j=;j<=nst->top;++j)//一趟后剩余的数字栈遍历打印
printf("%d ",nst->data[j]);
for(j=i+;j<cnt;++j) //一趟后剩余的后缀表达式数字或操作符打印
{
if(out[j].b==)
printf("%d ",out[j].u.num);
else printf("%c ",out[j].u.ch);
}
printf("\n");
}
return ;
}
/* 是否数字函数 */
bool isnumber(char ch){
if(ch>=''&&ch<='')
return true;
else
return false;
}
/* 是否栈空函数 */
bool isempty(stack *s){
if(s->top==-)
return true;
else
return false;
}
/* 压栈函数 */
void push(stack *s,char ch){
s->data[++s->top]=ch;
}
//参数int
void npush(nstack *s,int ch){
s->data[++s->top] = ch;
}
/* 弹栈函数 */
char pop(stack *s){
return s->data[s->top--];
}
int npop(nstack *s){
return s->data[s->top--];
}
/* 操作符优先级函数 */
int priority(char ch){
if(ch=='(')
return ;
if(ch=='+'||ch=='-')
return ;
if(ch=='*'||ch=='/')
return ;
if(ch=='^')
return ;
return ;
}
/* 取栈顶元素函数 */
char top(stack *s){
return s->data[s->top];
}
int ntop(nstack *s){
return s->data[s->top];
}

结构体数组形式

  三、中缀表达式转后缀表达式并计算,后缀表达式结构体数组形式,数字可多位,利用数字栈操作符栈

数字栈、操作符栈使用同一结构体,统一接口

 /*  c语言的中缀表达式转后缀表达式并计算结果
中缀表达式含双目运算符和小括号,数字操作数可以多位,
演示转变及计算过程
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#define N 256 /* 栈结构体 */
typedef struct{
short tag; //判断类型
union{
int* idata;
char* cdata;
}u;
int top;
}stack; /* 表达式结构体 */
typedef struct {
short tag;//判断类型
union {
int num;
char ch;
}u;
}EXPRESSION; /* 栈操作函数声明 */
void push(stack*, int);
int pop(stack*);
int top(stack*);
int priority(char);
bool isnumber(char);
bool isempty(stack*); int main()
{
int i,j,len,cnt;//字符串下标、长度变量 stack istack, cstack;//数字栈 操作符栈 istack.tag = ;
istack.u.idata = (int*)malloc(sizeof(int)*N);
istack.top = -; //操作符栈空 cstack.tag = ;
cstack.u.cdata = (char*)malloc(sizeof(char)*N);
cstack.top = -; //数字栈空 char str[N];//中缀表达式字符串
EXPRESSION out[N];//后缀表达式结构体数组
cnt = ;//后缀表达式数组下标
int sum = ;//累加数字 scanf("%s",str);//读取中缀表达式字符串
len = strlen(str);//读取的中缀表达式字符串长度
int flag = ;//是数字标识 /* 1.中缀表达式转后缀表达式(用操作符栈) */
for(i=; i<=len; i++)// 100*(2+3)-4 100 2 3 + * 4 -
{
/* 从字符串读取的字符为数字,插入到后缀表达式结构体数组 */
if(isnumber(str[i])){
sum = sum* + str[i] - '';//累加数字
flag = ;//是数字标识
continue;
}
/* 数字进后缀表达式结构体数组的数字 */
if(flag)
{
out[cnt].tag = ;
out[cnt++].u.num = sum;
flag = ;
sum = ;
}
/* 读取优先级高的非数字字符(字符')'优先级0) 或者 操作符栈为空 */
if(priority(str[i])>priority(top(&cstack))||isempty(&cstack))
{
push(&cstack, str[i]);
continue;
}
/* 读取的字符是右括号,一次处理完括号内数字\操作符\包括'('*/
if(str[i] == ')')
{
while(top(&cstack) != '(')
{
out[cnt].tag = ;
out[cnt].u.ch = top(&cstack); //操作符进后缀表达式数组的字符
cnt++;
pop(&cstack);
}
pop(&cstack);// '('
continue;
}
/* 处理括号外数字及操作符*/
while(!isempty(&cstack)&&top(&cstack)!='(')
{
out[cnt].tag = ;
out[cnt++].u.ch = top(&cstack);//操作符进后缀表达式数组的字符
pop(&cstack);
}
/* 低级别操作符入栈 */
if(str[i])
push(&cstack,str[i]);
}
/* 打印后缀表达式 */ //100 2 3 + * 4 - 100*(2+3)-4
for(i=;i<cnt;++i)
{
if(out[i].tag==)
printf("%d ",out[i].u.num);
else printf("%c ",out[i].u.ch);
}
printf("\n");
#ifdef N
/* 2.根据后缀表达式计算(用操作符栈\数字栈) */
for(i=;i<cnt;i++)
{
/* 从后缀表达式结构体数组读取,是数字压数字栈,
然后判断结构体数组是否读完 */
if(out[i].tag == ){
push(&istack,out[i].u.num);
continue;
}
else if(out[i].u.ch=='+'){//数字栈顶元素加到下面元素并弹出栈顶元素
istack.u.idata[istack.top-] += top(&istack);
pop(&istack);
}else if(out[i].u.ch=='-'){//同理减到下面元素并弹出栈顶元素
istack.u.idata[istack.top-] -= top(&istack);
pop(&istack);
}else if(out[i].u.ch=='*'){ //同理乘到下面元素并弹出栈顶元素
istack.u.idata[istack.top-] *= top(&istack);
pop(&istack);
}else if(out[i].u.ch=='/'){ //同理除到下面元素并弹出栈顶元素
istack.u.idata[istack.top-] /= top(&istack);
pop(&istack);
}else if(out[i].u.ch=='^'){//同理幂到下面元素并弹出栈顶元素
istack.u.idata[istack.top-]
= pow(istack.u.idata[istack.top-], top(&istack));
pop(&istack);
} for(j=;j<=istack.top;++j)//一趟后剩余的数字栈遍历打印
printf("%d ",istack.u.idata[j]);
for(j=i+;j<cnt;++j) //一趟后剩余的后缀表达式数字或操作符打印
{
if(out[j].tag==)
printf("%d ",out[j].u.num);
else printf("%c ",out[j].u.ch);
}
printf("\n");
}
#endif
return ;
} /* 是否栈空函数 */
bool isempty(stack *s){
return (s->top == -);
} /* 压栈函数 */
void push(stack *s, int ch){
if(s->tag == ){
s->u.cdata[++s->top] = (char)ch;
}
else{
s->u.idata[++s->top] = ch;
}
} /* 弹栈函数 */
int pop(stack *s){
if(s->tag == ){
return s->u.cdata[s->top--];
}
return s->u.idata[s->top--];
} /* 取栈顶元素函数 */
int top(stack *s){
if(s->tag == ){
return s->u.cdata[s->top];
}
return s->u.idata[s->top];
} /* 是否数字函数 */
bool isnumber(char ch){
return (ch>=''&&ch<='');
} /* 操作符优先级函数 */
int priority(char ch){
if(ch=='+'||ch=='-')
return ;
if(ch=='*'||ch=='/')
return ;
if(ch=='^')
return ;
if(ch=='(')
return ;
return ;
}

栈,统一接口

  四、中缀表达式计算

 /* c语言的中缀表达式计算*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#define N 256 /* 栈结构体 */
typedef struct{
short tag; //判断类型
union{
int* idata; //整形指针
char* cdata;//字符型指针
}u;
int top;
}stack; /* 栈操作函数声明 */
void push(stack*, int); //压栈
int pop(stack*); //出栈
int top(stack*); //栈顶元素
void calculate(stack *ist, stack *cst);//计算
bool isempty(stack*); //栈空
int priority(char); //运算符优先级
bool isnumber(char); //字符数字
char* StrOperation(char* r);//字符串整理
int match(char ch); //字符匹配 int main()
{
stack istack, cstack;//数字栈 运算符栈 istack.tag = ;
istack.u.idata = (int*)malloc(sizeof(int)*N);
istack.top = -; //数字栈空 cstack.tag = ;
cstack.u.cdata = (char*)malloc(sizeof(char)*N);
cstack.top = -; //运算符栈空 char str[N];//中缀表达式字符串
int sum = ;//累加数字 gets(str);//读取中缀表达式字符串(含空白符的字符串)
StrOperation(str); //整理字符串
printf("%s\n" ,str); int len = strlen(str);//读取的中缀表达式字符串长度
int flag = ;//是数字标识 for(int i=; i<=len ; i++) // 100*(2+3)-4 100 2 3 + * 4 -
{ //---------------------------------第一, 数字\运算符进栈
if(isnumber(str[i]))//累加数字
{
sum = sum* + str[i] - '';
flag = ;//是数字标识
continue;
}
//1.数字进栈
if(flag)/*为了保证最后一个数字进数字栈, 读到字符串结束标记时也要循环一次 */
{
push(&istack, sum);//数字进栈
flag = ;
sum = ;
}
//2.运算符栈入栈(高级运算符)
/* 栈空或运算符优先级比栈顶高,运算符入栈保证下面可以正常运算 */
if(priority(str[i])>priority(top(&cstack))||isempty(&cstack))
{
push(&cstack, str[i]);
continue;
}
//----------------------------------第二, 处理括号内数字\运算符
//3.处理括号里的操作数\运算符
/* 计算数字栈, 数字栈\运算符栈出栈 最后'('运算符出栈*/
if(str[i] == ')')
{
while(top(&cstack) != '(')
{
calculate(&istack,&cstack);
}
pop(&cstack);//'(' 出栈
continue; //返回为下次运算准备数字\运算符栈
}
//-----------------------------------第三, 处理括号外数字\运算符
//4.除了'('不处理, 循环处理数字栈\运算符栈
while(top(&cstack)!='('&&!isempty(&cstack))
{
calculate(&istack,&cstack);
}
//5.确保低级运算符入运算符栈
if(str[i]){ //确保最后的字符串结束标记, 不被读入运算符栈
push(&cstack,str[i]);
}
}
printf("%d\n",top(&istack));
return ;
} /* 是否栈空函数 */
bool isempty(stack *s){
return (s->top == -);
} /* 压栈函数 */
void push(stack *s, int ch){
if(s->tag == ){
s->u.cdata[++s->top] = (char)ch;
}
else{
s->u.idata[++s->top] = ch;
}
} /* 弹栈函数 */
int pop(stack *s){
if(s->tag == ){
return s->u.cdata[s->top--];
}
return s->u.idata[s->top--];
} /* 取栈顶元素函数 */
int top(stack *s){
if(s->tag == ){
return s->u.cdata[s->top];
}
return s->u.idata[s->top];
} /* 表达式运算 */
void calculate(stack *ist, stack *cst)
{
switch(top(cst)){
case '+':ist->u.idata[ist->top-] += top(ist);break;
case '-':ist->u.idata[ist->top-] -= top(ist);break;
case '*':ist->u.idata[ist->top-] *= top(ist);break;
case '/':ist->u.idata[ist->top-] /= top(ist);break;
case '^':ist->u.idata[ist->top-]
= pow(ist->u.idata[ist->top-], top(ist));break;
}
pop(ist);
pop(cst);
} /* 是否数字函数 */
bool isnumber(char ch){
return (ch>=''&&ch<='');
} /* 操作符优先级函数 */
int priority(char ch)
{
if(ch=='+'||ch=='-')
return ;
if(ch=='*'||ch=='/')
return ;
if(ch=='^')
return ;
if(ch=='(')
return ;
return ;
} /* 字符串处理函数 */
char* StrOperation(char* r){
if(r==NULL)
return NULL;
char* t = r;
while(*t)
{
if(match(*t)){
t++;
continue;
}
*t = '\0';
strcat(r,t+);
}
return r;
} /* 字符匹配函数 */
int match(char ch){
char key[] = "+-*/^()0123456789";
for(int i=; key[i]; ++i)
if(ch == key[i]) return ;
return ;
}

中缀表达式计算,包括整理字符串

  五、结构体数组表示中缀表达式

 #include <stdio.h>
#include <stdlib.h> typedef struct {
short tag;
union {
double num;
char ch;
}u;
}EXPRESSION; bool isnumber(char ch){
return (ch>=''&&ch<='');
} int main()
{
char str[] = "1.23*(15.1+33.26)"; EXPRESSION e[];
int index = , flag = ; for(int i=; str[i]; ++i)
{
if(isnumber(str[i])||str[i] == '.'){
if(flag){
e[index].u.num = atof(&str[i]);
e[index++].tag = ;
flag = ;
}
continue;
}
e[index].u.ch = str[i];
e[index++].tag = ;
flag = ;
} for(int i=; i<index; ++i){
if(e[i].tag) printf("%.2f", e[i].u.num);
else printf("%c", e[i].u.ch);
} return ;
}

字符串转浮点+字符

c语言,中缀表达式转后缀表达式并计算的更多相关文章

  1. 栈的简单应用之中缀表达式转后缀表达式(C语言实现逆波兰式)

    一.前言   普通人在书写计算式时会选择中缀表达式,这样符合人脑的认知习惯.可计算机处理时后缀表达式才能使处理速度更快,其原因是利用堆栈结构减少计算机内存访问.同时它也是一个很好锻炼栈这个数据结构的应 ...

  2. C语言- 基础数据结构和算法 - 09 栈的应用_中缀表达式转后缀表达式20220611

    09 栈的应用_中缀表达式转后缀表达式20220611 听黑马程序员教程<基础数据结构和算法 (C版本)>, 照着老师所讲抄的, 视频地址https://www.bilibili.com/ ...

  3. 利用stack结构,将中缀表达式转换为后缀表达式并求值的算法实现

    #!/usr/bin/env python # -*- coding: utf-8 -*- # learn <<Problem Solving with Algorithms and Da ...

  4. RPN-逆波兰计算器-中缀表达式转后缀表达式-javascript

    1.利用栈(Stack)来存储操作数和操作符: 2.包含中缀表达式转后缀表达式的函数,这个是难点,也是关键点: 2.1.将输入字符串转为数组: 2.2.对转换来的字符进行遍历:创建一个数组,用来给存储 ...

  5. 练习3.20 a 将中缀表达式转换为后缀表达式

    //将中缀表达式转换为后缀表达式 int main() { ; ]={,,,,,,,}; char tmp; PtrToStack s; s = CreateStack( MaxSize ); ) { ...

  6. NYOJ--257--郁闷的C小加(一)(中缀表达式变后缀表达式 )

    郁闷的C小加(一) 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 我们熟悉的表达式如a+b.a+b*(c+d)等都属于中缀表达式.中缀表达式就是(对于双目运算符来说 ...

  7. .net表达式计算器(中缀表达式转后缀表达式,支持20多个数学函数,支持函数嵌套)

    最近在网上查了一下表达工计算器的类库,发现Java版本的有一个比较成熟的叫W3EVal,好像是一个IBM工程师写的,.net就很少了(可能是我了解不够多),但投机取巧的实现思路有很多,比如: (1)将 ...

  8. hdu-1237 简单计算器---中缀表达式转后缀表达式

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1237 题目大意: 读入一个只包含 +, -, *, / 的非负整数计算表达式,计算该表达式的值. 思路 ...

  9. 中缀表达式得到后缀表达式(c++、python实现)

    将中缀表达式转换为后缀表达式的算法思想如下: 从左往右开始扫描中缀表达式 遇到数字加入到后缀表达式 遇到运算符时: 1.若为‘(’,入栈 2.若为’)‘,把栈中的运算符依次加入后缀表达式,直到出现'( ...

随机推荐

  1. windows 下 修改jmeter ServerAgent端口

    from:https://blog.csdn.net/wanglha/article/details/51281462 如果想修改UDP和TCP的端口该如何做呢,可以采用如下的方式: CMD命令进入S ...

  2. C#数组--(Array类的属性和方法)

    Array 类是 C# 中所有数组的基类,它是在 System 命名空间中定义.Array 类提供了各种用于数组的属性和方法,可看作扩充了功能的数组(但不等同数组),可以使用Array类的属性来对数组 ...

  3. win2012R2 的IIS报错HTTP404,报错在计算机上找不到服务W3SVC等等

    一.背景 今天远程给客户解决IIS的默认网页浏览找不到文件夹,报错HTTP404,找了很多原因,而且也报错在计算机上找不到服务W3SVC等等,如图所示: 二.原因 试了很多方法都不可以重装IIS都不行 ...

  4. list内含有元组或字典

    a=[(")] for k,v,i in a: print(k,v,i) 结果: 1 21 12 2 31 32 list里含元组,可以用这种遍历输出挨个元素 但list里含字典时,这样就只 ...

  5. pycharm配置QtDesigner

    QtDesigner C:\Qt\Qt5.12.2\5.12.2\mingw73_64\bin\designer.exe $ProjectFileDir$ Pyuic C:\Anaconda3\pyt ...

  6. C# deep copy List

    https://stackoverflow.com/questions/14007405/how-create-a-new-deep-copy-clone-of-a-listt 1. copy lis ...

  7. [转] jquery作者John Resig编写的微模板引擎:JavaScript Micro-Templating

    I've had a little utility that I've been kicking around for some time now that I've found to be quit ...

  8. MySQL数据库再回首

    前言: 数据库是程序员的数据源泉,加上近期 要开发DB可视化.性能分析的功能 重新回顾一下MySQL知识,以下是笔记: MySQL架构 MySQL基础理论 1.什么是关系型数据库? 关系型数据库,这个 ...

  9. smb 访问时 提示权限不够

    1. 确认 防火墙关闭和getenforce 为Permissive 状态. 关闭防火墙 service iptables stop 关闭  setenforce 0 2.windows 登录切换 身 ...

  10. css修改原生radio样式

    日常工作中经常会用到单选框radio,而原生样式不好看无法满足项目要求,模拟写一个又比较麻烦,所以写了一个改变原生样式的demo. 原生样式: 改变后的样式: 以下为demo代码: <!DOCT ...