subject

Infix to Postfix Write a C++ program that will accept infix expressions (like 5*(4+8)) and
convert them to postfix. You are to use Dijkstra's algorithm for converting.
Dijkstra's Algorithm:
Read in 1 line into a string
Print the string
while there are characters left to process in the string

| get a token (skip over blanks)
| if the token is a digit then output(token)
| else
|
| | if the token is '(' then push(token)
| | else
| |
| | | if the token is ')' then
| | |
| | | | while the top item is not '('
| | | | pop(temp) and output(temp);
| | | | pop(temp)
| | |
| | | else
| | |
| | | | if the stack is empty then push(token)
| | | | else
| | | |
| | | | | while the stack is not empty
| | | | | and the priority (token) <= priority (top item on the stack)
| | | | | pop(temp) and output(temp)
| | | | | push(token)
| | | |
| | |
| |
|

while the stack is not empty do pop(temp) and output(temp)
Precedence of the Operators:
operators : ^ * / + - (
precedence: 3 2 2 1 1 0
where ^ means exponentiation
input for the assignment:
2 + 3 * 5
2 + 3 * 5 ^ 6
2 + 3 - 5 + 6 - 4 + 2 - 1
2 + 3 * (5 - 6) - 4
2 * 3 ^ 5 * 6 - 4
(2 + 3) * 6 ^ 2
Output for the assignment
1: 2 + 3 * 5
235*+
2: 2 + 3 * 5 ^ 6
2356^*+
3: 2 + 3 - 5 + 6 - 4 + 2 - 1
23+5-6+4-2+1-
4: 2 + 3 * (5 - 6) - 4
2356-*+4-
5: 2 * 3 ^ 5 * 6 - 4
235^*6*4-
6: (2 + 3) * 6 ^ 2
23+62^*
You might also try:
7: ( ( ( ( 2 + 3 - 4 ) / 2 + 8 ) * 3 * ( 4 + 5 ) / 2 / 3 + 9 ) )
23+4-2/8+3*45+*2/3/9+
Programming Notes:
You are to write a well-composed program. The stack routines are to be
defined as methods in a class and are to be in a separate file.
//A sample c++ program to read a file 1 line at a time
#include
#include
#include
using namespace std;
int main()
{
string aline;
ifstream inData;
inData. open("infix. data");
while ( getline(inData, aline) )
{
cout << aline << endl;
}
inData. close();
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 22:00
What do the principles of notice, choice, onward transfer, and access closely apply to? a. privacyb. identificationc. retentiond. classification
Answers: 1
question
Computers and Technology, 23.06.2019 00:30
Which one of the following is considered a peripheral? a software b mouse c usb connector d motherboard
Answers: 2
question
Computers and Technology, 23.06.2019 01:30
How do you set up a slide show to play continuously, advancing through all the slides without requiring your interaction? a. click set up slide show, and then select the loop continuously until ‘esc' and show without narration options. b. click set up slide show, and then select the loop continuously until ‘esc' and use timings, if present options. c. click set up slide show, and then select the show presenter view and use timings, if present options. d. click set up slide show, and then select the show without animation and browsed at a kiosk (full screen) options.
Answers: 3
question
Computers and Technology, 23.06.2019 19:40
Use a physical stopwatch to record the length of time it takes to run the program. calculate the difference obtained by calls to the method system.currenttimemillis() just before the start of the algorithm and just after the end of the algorithm. calculate the difference obtained by calls to the method system.currenttimemillis() at the start of the program and at the end of the program so that the elapsed time includes the display of the result. use the value returned by the method system.currenttimemillis() just after the end of the algorithm as the elapsed time.
Answers: 3
You know the right answer?
Infix to Postfix Write a C++ program that will accept infix expressions (like 5*(4+8)) and
co...
Questions
question
Mathematics, 08.02.2021 19:40
question
Mathematics, 08.02.2021 19:40
question
Health, 08.02.2021 19:40
Questions on the website: 13722359