Skip to content

Instantly share code, notes, and snippets.

@dafr32
Last active August 29, 2015 13:57
Show Gist options
  • Save dafr32/9713077 to your computer and use it in GitHub Desktop.
Save dafr32/9713077 to your computer and use it in GitHub Desktop.
Odwrotna Notacja Polska
#include <iostream>
using namespace std;
int tab[100];
int poz=-1;
int n=100;
void Push(int x)
{
if (poz<n) tab[++poz]=x;
}
int pop()
{
if (poz>=0) return tab[poz--];
}
int main()
{
string W;
int k=-1;
int suma=0;
cout << "Podaj ciag wartosci:";cin>>W;
for (int i=0;i<W.length();i++)
{
int znak = W[i];
int Z1,Z2;
switch(znak)
{
case 43 : Push(pop()+pop());break; //+
case 42 : Push(pop()*pop());break; //*
case 45 : Z2=pop(); Z1=pop(); Push(Z1-Z2);break; //-
case 47 : Z2=pop(); Z1=pop(); Push(Z1/Z2);break; //-
default : Push(znak-48);break;
}
}
cout << "suma=" << tab[0]<< endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment