The following problem comes from Appendix 1 of the Stalings text The steps are as follows: 1. Examine the next element i

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

The following problem comes from Appendix 1 of the Stalings text The steps are as follows: 1. Examine the next element i

Post by answerhappygod »

The Following Problem Comes From Appendix 1 Of The Stalings Text The Steps Are As Follows 1 Examine The Next Element I 1
The Following Problem Comes From Appendix 1 Of The Stalings Text The Steps Are As Follows 1 Examine The Next Element I 1 (75.92 KiB) Viewed 30 times
The following problem comes from Appendix 1 of the Stalings text The steps are as follows: 1. Examine the next element in the input 2. Fit is an operand, output it in other words, remove it from the input string and write out to the output string 3. If it is an opening parenthesis, push it onto (move it to) the stack 4. It is an operator (not a function), then a. the top of the stack is an opening parenthesis, then push the operator. b. If the operator has higher priority than the top of the stack (multiply and divide have higher pronty than add and subtract), then push the operator c Else, leave the operator in the input string alone (leaved in the input string untouched), and instead pop the operator from the stack to output, and repeat step 4 5. It is a closing parenthesis, pop operators from the stack to the output until at opening parenthesis is encountered Then pop and discard the opening parenthesis from the stack and then discard the closing parenthesis from your input sting 6. If there is more input, go to step 1. 7. If there is no more input, unstack the remaining operands to the output. When you are done, there should be no input streng nor stack pemaining - everything should be in the output string Input Output Stack Reason A+BxC+( DE) XF empty empty 2. A is Operand, output A + BxC++E)KF A empty 4.b. + is Op'r, prec> blank, push BXC +(+E) FA 2. Bis Op'd output B *C+(D+E) FAB 4.b. x is Op'r, prect push C+(D+EF AB 2. C is Op'd output. C +(D+E) XF ABC 4.c. + is Op'd prec<x, pop X +(D+E) FABCK 40.is Op'd prec = x Pop- +(D+E) F ABCx+ 4.b. + is Op'd, prec> blank, push (D+EXF ABCX 3.push D+EF ABCK+ 2. Dis Op'd output D +E) F ABCx+D 4.a. top is (push + EXF ABCx+D 2. Eis Op'd output E F ABCX DE + 5.) pop pop & disc (disc) F ABCX+DE+ 4b. x is Op'r prec> push x FAB Cx+DE 2. Fis Op 'd, output emply ABCX+DE+F 7. No input remains unstack all. empty ABCx+DE+Fx+ empty + X + x +x + + + + + Reason Input Output (a-b)-c-d%e empty Stack empty
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply