Помогите собратья я уже полностью запутался!
<code>#include<stdio.h>
#include<stdlib.h>
struct stk{
char val;
struct stk *next;
};
struct stk *in(struct stk *p, char c){
struct stk *t=NULL;
t=malloc(sizeof(struct stk));
t->val=c;
t->next=p;
p=t;
return p;
}
char del(struct stk **p){
struct stk *t;
char c;
if(*p==NULL) return '\0';
t=*p;
c=t->val;
*p=t->next;
free(t);
return c;
}
int prio(char c){
if(c=='*' || c=='/') return 3;
if(c=='+' || c=='-') return 2;
//if(c==')') return 1;
//if(c=='(') return 0;
}
void analising(char *expr, char *out_expr){
int i=0, o_i=0;
struct stk *p=NULL; //our stack
while(expr!='\0'){
if(expr>='a' && expr<='z'){//puting symbol in output string
out_expr[o_i]=expr;
o_i++;
i++;
continue;
}
if(expr=='('){
p=in(p,expr);
i++;
continue;
}
if(expr=='+'||expr=='-'||expr=='*'||expr=='/'){
if(p==0){ //if stack is empty insert operation to stack
p=in(p,expr);
i++;
continue;
}
if(p!=0){ //if stack is't empty extrct operations with big or equation priority
p=in(p,expr);
struct stk *t=p->next;
while(t!=0){
if(t->val=='(') break;
if(prio(t->val)>=prio(p->val)){//if priority is > || >=
out_expr[o_i]=del(&t);
o_i++;
}
else t=t->next;
}
i++;
continue;
}
}
if(expr==')'){//if
struct stk *t=p;
while(t->val!='('){
out_expr[o_i]=del(&t);
o_i++;
}
i++;
del(&t);//deleting '('
continue;
}
}
if(p!=0){
while(p!=0){
out_expr[o_i]=del(&p);
o_i++;
}
}
out_expr[o_i]='\0';
}
main(){
char expr[80], out_expr[80];
printf("Input expression: ");
fflush(stdin);
scanf("%s", expr);
analising(expr, out_expr);
printf("%s",out_expr);
return 0;
}</code>