code just turns infix to infix but I can't figure out why?, my code is supposed to turn infix to rpn but this line here:
while( !presedence.empty() && presedence.top() >= num2 )
{
output.push(oprators.top());
oprators.pop();
presedence.pop();
}
is the one that causes error, I think, because if I remove the '=' it just works, be it without allowing letters of the same precedence to join the output queue.
full code:
#include <cmath>
#include <stack>
#include<queue>
#include <iostream>
#include <regex>
#include <vector>
#include <thread>
#include <bitset>
#include <ctime>
#include <string.h>
#include <math.h>
#include <bits/stdc++.h>
#define M_PI 3.14159265358979323846264338327950288419716939937510582097494
#include<windows.h>
#define gkey GetAsyncKeyState
using namespace std;
#define rxs regex_search
#define loop while(true)
double a;
double num1;
double c3 = 299792458;
double c3sq = 89875517873681764;
int mc;
string again;
stack<int> presedence;
stack<string> oprators;
queue<double> numbers;
stack<char> test;
double num5;
double num6;
int E;
int abrt = 0;
double num2;
double ans = num1 + num2;
int num;
int numalt = 0;
int numaltt = 0;
//int nums [] = {srand(time(0));rand();}
bool autoregex(string test){
regex e ("[-+]?([0-9]*\.[0-9]+|[0-9]+)");
if (regex_match (test,e))
return true;
return false;
}
bool autrege(string test){
regex aret("SIN|LOG|sqrt|sin|log|tan|pi|e|ln|EE|[^0-9a-z$@#&\]");
if (regex_match (test,aret)){
return true;
}
else{
return false;}
}
void namehere(string test){
if(autrege(test) == true){
regex bret("[+-]");
regex cret("[/*xX]");
regex dret("SIN|LOG|sqrt|sin|log|tan|pi|!|e|ln|EE|\\^");
regex omega("\\)");
regex canmae("\\(");
if (regex_match (test,bret)){num2 = 1;};
if (regex_match (test,cret)){num2 = 2;};
if (regex_match (test,dret)){num2 = 3;};
if (regex_match (test,omega)){num2 = 4;numaltt = numaltt + 1;};
if (regex_match (test,canmae)){num2 = 4;numalt = numalt + 1;};
}
}
int main()
{
vector<double> vec;
again = "n";
while(again == "n"&&abrt == 0){
// queue<double> numbers; stack<int> pres;
queue<string> output;
int test;
string name;
getline(cin, name);
istringstream iss(name);
string token;
while(iss >> token)
{
if(autoregex(token) == true){
output.push(token);
}
if(autrege(token)== true)//token area
{
namehere(token);
num6++;
if(num2 == -1){cout<<"wrong move: ";again = "n";again = "y";cout<<num2<<endl;}
while(presedence.empty() == 1 && oprators.empty() == 1)
{
presedence.push(num2);
oprators.push(token);
}
while(presedence.top() < num2 && !presedence.empty())
{
oprators.push(token);
presedence.push(num2);
}
while(presedence.top() >= num2 && !presedence.empty())
{
output.push(oprators.top());
oprators.pop();
presedence.pop();
}
//3-T 2-ME
}
}
while(presedence.empty() != 1 && oprators.empty() != 1){ output.push(oprators.top());
oprators.pop();presedence.pop();}
while(!output.empty()){cout<<output.front()<<", ";output.pop();}
}
while(again != "n"&&abrt == 0){
}
}
it breaks when I try to see if the top of the operator stack is greater than the current operator,any reasons?