B
bushido
#include<iostream>
#include<vector>
#include<string>
using namespace std;
class Stack
{
public :
Stack();
void push(char&);
void pop();
char getpop();
void output();
private:
vector<char> _vector;
int topOfStack;
};
Stack::Stack():topOfStack(-1){}
void Stack:ush(char &x)
{
topOfStack++;
_vector.push_back(x);
}
void Stack:op()
{
topOfStack--;
}
char Stack::getpop()
{
return _vector[topOfStack--];
}
void Stack:utput()
{
for(int i = topOfStack-1; i != -1 ; i--)
{
cout<<"item "<<i<<"= "<<_vector<<endl;
}
}
int main()
{
string _str;
cin>>_str;
Stack _stack;
for(int i=0 ;i != _str.size(); i++)
{
if((_str != '+') && (_str != '*'))
{
_stack.push(_str);
}
else if(_str == '+')
{
int temp;
temp = _stack.getpop() + _stack.getpop();
char ctemp = (char)temp;
_stack.push(ctemp);
}
else if(_str == '*')
{
int temp;
temp = _stack.getpop() * _stack.getpop();
char ctemp = (char)temp;
_stack.push(ctemp);
}
}
cout<<endl;
_stack.output();
return 0;
}
I have problem in line
else if(_str == '+')
{
int temp;
temp = _stack.getpop() + _stack.getpop();
char ctemp = (char)temp;
_stack.push(ctemp);
}
else if(_str == '*')
{
int temp;
temp = _stack.getpop() * _stack.getpop();
char ctemp = (char)temp;
_stack.push(ctemp);
}
b'coz ex. 56+
5 => 53
6 => 54
sum is 107 => k but i want 11 not k and push in vector is 11 plese
help.
#include<vector>
#include<string>
using namespace std;
class Stack
{
public :
Stack();
void push(char&);
void pop();
char getpop();
void output();
private:
vector<char> _vector;
int topOfStack;
};
Stack::Stack():topOfStack(-1){}
void Stack:ush(char &x)
{
topOfStack++;
_vector.push_back(x);
}
void Stack:op()
{
topOfStack--;
}
char Stack::getpop()
{
return _vector[topOfStack--];
}
void Stack:utput()
{
for(int i = topOfStack-1; i != -1 ; i--)
{
cout<<"item "<<i<<"= "<<_vector<<endl;
}
}
int main()
{
string _str;
cin>>_str;
Stack _stack;
for(int i=0 ;i != _str.size(); i++)
{
if((_str != '+') && (_str != '*'))
{
_stack.push(_str);
}
else if(_str == '+')
{
int temp;
temp = _stack.getpop() + _stack.getpop();
char ctemp = (char)temp;
_stack.push(ctemp);
}
else if(_str == '*')
{
int temp;
temp = _stack.getpop() * _stack.getpop();
char ctemp = (char)temp;
_stack.push(ctemp);
}
}
cout<<endl;
_stack.output();
return 0;
}
I have problem in line
else if(_str == '+')
{
int temp;
temp = _stack.getpop() + _stack.getpop();
char ctemp = (char)temp;
_stack.push(ctemp);
}
else if(_str == '*')
{
int temp;
temp = _stack.getpop() * _stack.getpop();
char ctemp = (char)temp;
_stack.push(ctemp);
}
b'coz ex. 56+
5 => 53
6 => 54
sum is 107 => k but i want 11 not k and push in vector is 11 plese
help.