I need to implement an infix to postfix calculator using stacks and queues in C++. I know what algorithm to follow but I'm having trouble starting. My program should go like the following:
Enter a valid infix expression: 3 + 4 * 5 / 6
The resulting postfi expression is: 3 4 5 * / 6 +
The result is: 6.3333
So I need to read input from the command line and that's where I'm having the problem. This is my code so far:
using namespace std;
#include <iostream>
#include <stdlib.h>
#include <stack>
#include <queue>
int main() {
stack <string> convert;
stack <string> evaluate;
queue <string> store;
string data;
float num;
cout << "Enter a valid infix expression: ";
while (getline(cin, data)) {
store.push(data);
}
return 0;
}
My problem here is how do I stop the loop and how can I get the numbers from the string input so I can push them into the queue to print them later on? My code is pushing the entire string into the the first slot in the queue. Hope someone can help.
Thank you