Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C++ by Vamos ( 16 years ago )
void Ex1()
{
string input;
cout << "Podaj dane na wejscie: ";
cin.ignore();
getline(cin,input);
cout << "Wyrazenie w ONP: " << Convert_To_ONP(input);
}
string Convert_To_ONP(string input)
{
STOS<string> stos; //mam zadkelarowaną strukturę stosu w pliku stos.h
string::iterator it;
string output;
string znak;
string szczyt_stosu;
int znak_int;
for ( it=input.begin() ; it < input.end(); it++ )
{
znak = *it;
znak_int = static_cast<int>(*it);
if((znak_int>47)&&(znak_int<58)) output.append(znak);
if((znak_int==42)||(znak_int==43)||(znak_int==45)||(znak_int==47))
{
stos.pop(szczyt_stosu);
stos.push(szczyt_stosu);
while((((znak_int==42)||(znak_int==47))&&((szczyt_stosu=="*")||(szczyt_stosu=="/")))||(((znak_int==43)||(znak_int==45))&&((szczyt_stosu=="*")||(szczyt_stosu=="/"))))
{
stos.pop(szczyt_stosu);
output.append(szczyt_stosu);
stos.pop(szczyt_stosu);
stos.push(szczyt_stosu);
}
stos.push(znak);
}
if(znak_int==40) stos.push(znak);
if(znak_int==41)
{
do
{
stos.pop(szczyt_stosu);
output.append(szczyt_stosu);
stos.pop(szczyt_stosu);
stos.push(szczyt_stosu);
}while(szczyt_stosu!="(");
stos.pop(szczyt_stosu);
}
}
while(stos.StanStosu()!=2)
{
stos.pop(szczyt_stosu);
if(szczyt_stosu=="(") continue;
output.append(szczyt_stosu);
}
Revise this Paste