Lecture 8 Stack II PDF
Document Details
Uploaded by LowCostAphorism
Uttara University
ARIFATUN NESA
Tags
Summary
This document discusses various applications of stacks, focusing on converting infix expressions to postfix notation, evaluating postfix expressions, and reversing data. It also explores the importance of operator priorities in evaluating expressions. The document presents exercises for practice and example problems to solidify the concepts.
Full Transcript
Stack ARIFATUN NESA Lecturer Department of CSE Uttara University Stack Application 1. Checking the validity of an arithmetic expression 2. Converting an infix arithmetic expression to its postfix format. 3. Evaluating a postfix expression. 4. Reverse a given set of data...
Stack ARIFATUN NESA Lecturer Department of CSE Uttara University Stack Application 1. Checking the validity of an arithmetic expression 2. Converting an infix arithmetic expression to its postfix format. 3. Evaluating a postfix expression. 4. Reverse a given set of data, such as a string or a list by pushing each element onto the stack and then popping them off, the data is reversed due to the LIFO property. 5. Function Calls and Recursion. 2 Stack Application a. Checking the validity of an arithmetic expression Stack Application a. Checking the validity of an arithmetic expression Stack Application b. Converting an infix arithmetic expression to its postfix format. Stack Application b. Converting an infix arithmetic expression to its postfix format. Stack Application b. Converting an infix arithmetic expression to its postfix format. Stack Application b. Converting an infix arithmetic expression to its postfix format. Exercises Convert Infix to postfix using stack Ex. 1: 2+4/5*(5-3)^5^4 Ex. 2: A+B/C*(D-A)^F^H Ex.3: K + L - M*N + (O^P) * W/U/V * T + Q Stack Application c. Evaluating a postfix expression. Stack Application c. Evaluating a postfix expression. Stack Application c. Evaluating a postfix expression. Stack Application c. Reverse a given set of data, such as a string or a list by pushing each element onto the stack and then popping them off, the data is reversed due to the LIFO property. Exercises Checking the validity of an arithmetic expression using stack [e.g.: a. (A-B)*[C/(D+E)+F], b. (2+4) * (4+6), c.100 * {( 2 + 12 ) etc..try from online resources.] How many ways can a expression can be expressed. Write their Name providing an expression. Why to use prefix and postfix notation while having simple infix notation? Converting an infix arithmetic expression to its postfix format (a. with stack, b. without stack). a. A + B * C + D b. (A + B) * (C + D) c. A * B + C * D d. A + B + C + D e. 10 + 3 * 5 / (16 - 4) f. 2+4/5*(5-3)^5^4 g. A+B/C*(D-A)^F^H, h. K + L - M*N + (O^P) * W/U/V * T + Q Evaluating a postfix expression. a. 100 200 + 2 / 5 * 7 + b. 17 10 + 3 * 9 / c. 2 5 3 6 + * * 5 / 2 - d. 2 4 5 5 3 -5 ^ 4 ^ * / +