to add a new function is that each expression should start with-sharp and end with-sharp. Ask the boss to write the complete code.
this is main
-sharpinclude <stdio.h>
-sharpinclude <stdlib.h>
-sharpinclude <string.h>
-sharpinclude <math.h>
-sharpinclude "stack.h"
int main(void){
int i,j,len,cnt;
OPTR *st=(OPTR*)malloc(sizeof(OPTR));//
EXPT *nst=(EXPT*)malloc(sizeof(EXPT));//
char str[85];
char out[85];//
printf("\n");
scanf("%s",str);//
nst->top=-1;
st->top=-1;
cnt=0;
len=strlen(str);//
for(i=0;i<len;iPP){
if(isnumber(str[i]))
out[cntPP]=str[i];
else{
if(str[i]=="("||isempty(st)){
push(st,str[i]);
continue;
}
if(str[i]==")"){
while(top(st)!="("){
out[cntPP]=top(st);
pop(st);
}
pop(st);
continue;
}
while(!isempty(st)&&top(st)!="("&&priority(str[i])<=priority(top(st))){
out[cntPP]=top(st);
pop(st);
}
push(st,str[i]);//
}
}
//Out
while(!isempty(st)){
out[cntPP]=top(st);
pop(st);
}
out[cnt]="\0";
for(i=0;i<cnt;PPi)
printf("%c ",out[i]);
printf("\n");
for(i=0;i<cnt;iPP){
if(isnumber(out[i])){
npush(nst,out[i]);
continue;
}else if(out[i]=="+"){
nst->data[nst->top-1]+=ntop(nst);
npop(nst);
}else if(out[i]=="-"){
nst->data[nst->top-1]-=ntop(nst);
npop(nst);
}else if(out[i]=="*"){
nst->data[nst->top-1]*=ntop(nst);
npop(nst);
}else if(out[i]=="/"){
nst->data[nst->top-1]/=ntop(nst);
npop(nst);
}
for(j=0;j<=nst->top;PPj)
printf("%d ",nst->data[j]);
for(j=i+1;j<cnt;PPj)
printf("%c ",out[j]);
printf("\n");
}
return 0;
}
this is stake
typedef struct{
char data[85];
int top;
}OPTR;
typedef struct{
int data[85];
int top;
}EXPT;
//
bool isnumber(char ch){
if(ch>="0"&&ch<="9")
return true;
else
return false;
}
//
bool isempty(OPTR *s){
if(s->top==-1)
return true;
else
return false;
}
//
void push(OPTR *s,char ch){
s->data[PPs->top]=ch;
}
void npush(EXPT *s,char ch){
s->data[PPs->top]=ch-"0";
}
//
char pop(OPTR *s){
return s->data[s->top--];
}
int npop(EXPT *s){
return s->data[s->top--];
}
//
int priority(char ch){
if(ch=="(")
return 0;
if(ch=="+"||ch=="-")
return 1;
if(ch=="*"||ch=="/")
return 2;
return 0;
}
//
char top(OPTR *s){
return s->data[s->top];
}
//
int ntop(EXPT *s){
return s->data[s->top];
}