Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct{
- int broj;
- //char znak;
- //int isChar=1;
- struct node* next;
- }node;
- node* Head=NULL;
- node* Tail=NULL;
- /*
- void pushC(char c)
- {
- node* new=(node*)malloc(sizeof(node));
- new->znak=c;
- new->next=NULL;
- if(Head==NULL)
- {
- Head=new;
- Tail=new;
- return;
- }
- Tail->next=new;
- Tail=new;
- }*/
- void push(int c)
- {
- node* new=(node*)malloc(sizeof(node));
- new->broj=c;
- //new->isChar=0;
- new->next=NULL;
- if(Head==NULL)
- {
- Head=new;
- Tail=new;
- return;
- }
- Tail->next=new;
- Tail=new;
- }
- int pop()
- {
- if(Head==Tail)
- {
- int a=Head->broj;
- free(Head);
- Head=Tail=NULL;
- return a;
- }
- node* c=Head;
- while(c->next!=Tail)
- {
- c=c->next;
- }
- int a=Tail->broj;
- free(Tail);
- Tail=c;
- c->next=NULL;
- return a;
- }
- void report()
- {
- node* tmp=Head;
- int i=0;
- while(tmp)
- {
- if(i) printf(" -> ");
- printf("%i",tmp->broj);
- tmp=tmp->next;
- i++;
- }
- }
- void radi(char* s)
- {
- int i=0;
- int broj=0;
- while(s[i])
- {
- if(s[i]>='0' && s[i]<='9')
- {
- while(s[i]!=' ')
- {
- int k=s[i]-'0';
- broj=broj*10+k;
- i++;
- }
- push(broj);
- //printf("%i ",broj);
- broj=0;
- }
- if(s[i]=='+')
- {
- int a=pop();
- int b=pop();
- push(a+b);
- }
- if(s[i]=='-')
- {
- int a=pop();
- int b=pop();
- push(b-a);
- }
- if(s[i]=='*')
- {
- int a=pop();
- int b=pop();
- push(a*b);
- }
- if(s[i]=='/')
- {
- int a=pop();
- int b=pop();
- push(b/a);
- }
- i++;
- }
- printf("\t %i ",pop());
- }
- int main()
- {
- char c[50];
- gets(c);
- radi(c);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement