Содержание
- 2. Objectives Understands the concepts of stacks Representation of stacks as data structure Different method for implementing
- 3. What is a stack? It is an ordered group of homogeneous items of elements. Elements are
- 4. Use of stack in Computer Science Consider an example, where we are executing function A. main()
- 5. Use of stack in Computer Science In the course of its execution, function A calls another
- 6. The system stack ensures a proper execution order of functions. Therefore, stacks are frequently used in
- 7. Operation on Stack push(i) to insert the element i on the top of the stack pop(
- 8. ARRAY REPRESENTATION OF STACKS In the computer’s memory, stacks can be represented as a linear array.
- 9. Algorithm for PUSH operation
- 12. PUSH operation
- 13. LINKED REPRESENTATION OF STACK Stack may be created using an array. This technique of creating a
- 14. Algorithm for PUSH operation of Stack implemented using Linked list
- 15. Algorithm for POP operation of Stack implemented using Linked list
- 16. Algorithm for PUSH operation Algorithm for POP operation
- 17. APPLICATIONS OF STACKS Parentheses checker Conversion of an infix expression into a postfix expression Evaluation of
- 18. Parentheses Checker Stacks can be used to check the validity of parentheses in any algebraic expression.
- 19. Algorithm: Declare a character stack S. Now traverse the expression string exp. If the current character
- 21. Pseudo code: Parenthesis Matching valid = true /* assuming that the string is valid*/ s =
- 22. Mathematical Notation Translation prefix (polish) postfix (reverse polish)
- 23. Mathematical Notation Translation Infix – prefix (polish) Infix – postfix (reverse polish) The fundamental property of
- 24. Conversion of an Infix Expression into a Postfix Expression An algebraic expression may contain parentheses, operands,
- 25. Algorithm Infix Expression to a Postfix Expression
- 26. Example
- 27. Evaluation of a Postfix Expression
- 28. Evaluation of a Postfix Expression
- 29. Example
- 30. Infix to Prefix Expression
- 31. Step 1. Push “)” onto STACK, and add “(“ to start of the A. Step 2.
- 32. Method2- Infix Expression to a Prefix Expression
- 33. Step 1. Push “)” onto STACK, and add “(“ to start of the A. Step 2.
- 35. Evaluation of a Prefix Expression
- 36. Example
- 38. Скачать презентацию