#include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;
class queue
{ public:
int size;
char elmnt[50];
int front;
int rear;
int isempty();
void enqueue(int e);
int dequeue();
queue()
{size=20;
front=-1;
rear=-1;
}
};
int queue::isempty()
{if(front==-1)
{cout<<"Empty";
return 1;
}
else
return 0;
}
void queue::enqueue(int e)
{ rear=(rear+1)%size;
elmnt[rear]=e;
if(front==-1)
front=0;
}
int queue::dequeue()
{ int w=0;
if(isempty());
else
{w=elmnt[front];
if(front==rear)
{front=-1;
rear=-1;
}
else
front=(front+1)%size;
}
return(w);
}
int main()
{queue s;int j,i,c[2],ctr=-1,z,x,t,k;char arr[50];
cin.getline(arr,50);
k=strlen(arr);
for(i=0;i<k;i++)
{if(arr[i]=='+'||arr[i]=='-'||arr[i]=='*'||arr[i]=='/')
{for(j=0;j<i-2;j++)
{x=s.dequeue();s.enqueue(x);
}
for(j=i-2;j<i;j++)
{c[++ctr]=s.dequeue();
}
ctr=-1;
if(arr[i]=='+')
z=c[0]+c[1];
else if(arr[i]=='-')
z=c[0]-c[1];
else if(arr[i]=='*')
z=c[0]*c[1];
else
z=c[0]/c[1];
s.enqueue(z);
}
else
{t=arr[i]-48;
s.enqueue(t);}
}
x=s.dequeue();
cout<<x;
}
#include<cstdlib>
#include<cstring>
using namespace std;
class queue
{ public:
int size;
char elmnt[50];
int front;
int rear;
int isempty();
void enqueue(int e);
int dequeue();
queue()
{size=20;
front=-1;
rear=-1;
}
};
int queue::isempty()
{if(front==-1)
{cout<<"Empty";
return 1;
}
else
return 0;
}
void queue::enqueue(int e)
{ rear=(rear+1)%size;
elmnt[rear]=e;
if(front==-1)
front=0;
}
int queue::dequeue()
{ int w=0;
if(isempty());
else
{w=elmnt[front];
if(front==rear)
{front=-1;
rear=-1;
}
else
front=(front+1)%size;
}
return(w);
}
int main()
{queue s;int j,i,c[2],ctr=-1,z,x,t,k;char arr[50];
cin.getline(arr,50);
k=strlen(arr);
for(i=0;i<k;i++)
{if(arr[i]=='+'||arr[i]=='-'||arr[i]=='*'||arr[i]=='/')
{for(j=0;j<i-2;j++)
{x=s.dequeue();s.enqueue(x);
}
for(j=i-2;j<i;j++)
{c[++ctr]=s.dequeue();
}
ctr=-1;
if(arr[i]=='+')
z=c[0]+c[1];
else if(arr[i]=='-')
z=c[0]-c[1];
else if(arr[i]=='*')
z=c[0]*c[1];
else
z=c[0]/c[1];
s.enqueue(z);
}
else
{t=arr[i]-48;
s.enqueue(t);}
}
x=s.dequeue();
cout<<x;
}
No comments:
Post a Comment