2.1
![](https://img-blog.csdnimg.cn/c7183bd2bffd438ba0cb7454ae75b6e1.png)
#include <stdio.h>
#include <stdlib.h>
#include "list.h" // 请不要删除,否则检查不通过
int compute_reverse_polish_notation(char *str){
Stack S;
init_stack(&S);
int i=0,x,y,res,number_to_push;
while(str[i]!='\0'){
if (str[i] != ' ') {
if(str[i]>='0'&&str[i]<='9'){
number_to_push=0;
while (str[i] != ' ' && str[i]) {
number_to_push = number_to_push * 10 + (str[i] - '0');
i++;}
push(&S,number_to_push);
}else {
pop(&S,&x);
pop(&S,&y);
switch(str[i]){
case '+':{ res =x+y; break;}
case '-': {res =y-x; break;}
case '*': {res =x*y;break;}
case'/' :{res =y/x;break; }
case'%' :{res =y%x;break;}}
push(&S,res);
}
}
i++;
}
pop(&S,&res);
return res;
}
2.2 ![](https://img-blog.csdnimg.cn/f15d6be7a91a48f59708b14c605f2064.png)
#include <stdio.h>
#include <stdlib.h>
#include "list.h" // 请不要删除,否则检查不通过
bool init_queue(LinkQueue *LQ)
{
*LQ=(LinkQueue)malloc(sizeof(LinkQueueNode));
if((*LQ)==NULL) return 0;
(*LQ)->next=*LQ;
return 1;
}
bool enter_queue(LinkQueue *LQ, ElemType x)
{
LinkQueue p;
p=(LinkQueue)malloc(sizeof(LinkQueueNode));
if(!p) return 0;
p->data=x;
p->next=(*LQ)->next;
(*LQ)->next=p;
*LQ=p;
return 1;
}
bool leave_queue(LinkQueue *LQ, ElemType *x)
{
LinkQueue p;
if((*LQ)->next==*LQ)
return 0;
p=(*LQ)->next->next;//指向第一个元素
*x=p->data;
if((*LQ)->next->next==(*LQ)){//两个节点
*LQ=(*LQ)->next;
(*LQ)->next=*LQ;free(p);
} else{
(*LQ)->next->next=(*LQ)->next->next->next;
free(p);
}
return 1;
}