caly
public text v1 · immutable
#include <iostream>
#include <string>
using namespace std;
char tab[]={'+','-','*','/','%','^','(',')'}; // deklarowanie tablicy znakow
int roz_tab=8;
string wyr_1; //definicja inputu
string wyr_2; //definicja outputu
string wyr_3;
string word3;
int a;
class Stack{
public:
Stack(void)
{
head=NULL;
};
void Push(char c)
{
head = new StackElement(c,head);
};
//bool IsEmpty {return head==NULL};
char Pop(void)
{
StackElement *temp = head;
char result = head->_c;
head=head->_next;
delete temp;
return result;
};
private:
class StackElement
{
public:
StackElement(char c, StackElement *next)
{
_c=c;
_next=next;
};
char GetChar()
{
return _c;
};
char _c;
StackElement *_next;
};
StackElement *head;
};
Stack S1;
string ReadToken(string word2)
{
word3="";
int ilosc=0;
int j=0;
for(int i=0;i<word2.size();i++)
{
if (((word2[i]<91)&&(word2[i]>64))||((word2[i]<123)&&(word2[i]>96))) //jezeli jest litera
word3+=word2[i];
else
{
if ((word2[i]<58)&&(word2[i]>47)) //jezeli jest liczba
word3+=word2[i];
else
{
while(j<(roz_tab-1)) //jezeli jest w tablicy
{
if((word2[i])!=(tab[j])) j++;
else
{
if (word2[i]==tab[6])
{
ilosc++;
cout<<"ilosc "<<ilosc<<endl;
S1.Push(word2[i]);
cout<<"zapisane aaaa "<<word2[i]<<endl;
break;
};
if (word2[i]==tab[7])
{
cout<<"aaaaa"<<endl;
if (ilosc>0)
{
string word1;
while(word1[0]!=tab[6])
{
word1=S1.Pop();
cout<<"zdjete "<<word1<<endl;
word3+=word1;
};
}
break;
}
S1.Push(word2[i]);cout<<"zapisane BBBB "<<word2[i]<<endl; break;
}; //end of while
}
}
}
} //end of if1
//word3+=S1.Pop();
//word3+=S1.Pop();
return word3;
}//end of function
/*string ConverToRPN(string)
{
} */
void PrintResult(string word1)
{
cout<<"expresion before RPN -->"<<word1<<endl;
}
main()
{
//cout<<tab[5]<<endl;
cout<<"podaj wyrazenie"<<endl;
cin>>wyr_1;
a=wyr_1.size();
PrintResult(wyr_1);
cout<<"dlugosc to "<<a<<endl;
wyr_2=ReadToken(wyr_1);
cout<<wyr_2<<"to co z funkcji "<<endl;
cout<<word3<<endl;
cin>>wyr_3;
}