Select Git revision
cours_13.md
Forked from
algorithmique / cours
Source project has a limited visibility.
eval_post.c 756 B
#include <stdio.h>
#include <stdlib.h>
#include "pile_ptr_int.h"
void main(int argc,char** argv) {
pile stack_nb = pile_creer();
int res,nb1,nb2;
for (int i=1;i<argc;i++) {
if ( argv[i][0] < '0' || '9' < argv[i][0]) {
nb1 = pile_depiler(&stack_nb);
nb2 = pile_depiler(&stack_nb);
}
switch(argv[i][0]) {
case '+':
res = nb2+nb1;
break;
case '-':
res = nb2-nb1;
break;
case 'x':
res = nb2*nb1;
break;
case '/':
res = nb2/nb1;
break;
default :
res = atoi(argv[i]);
}
pile_empiler(&stack_nb,res);
}
printf("%d\n",pile_depiler(&stack_nb));
}