Queue Applications Lecture 31 Mon, Apr 9, 2007.

Slides:



Advertisements
Similar presentations
INFIX, PREFIX, & POSTFIX EXPRESSIONS. Infix Notation We usually write algebraic expressions like this: a + b This is called infix notation, because the.
Advertisements

Stacks & Their Applications COP Stacks  A stack is a data structure that stores information arranged like a stack.  We have seen stacks before.
Expression Trees What is an Expression tree? Expression tree implementation Why expression trees? Evaluating an expression tree (pseudo code) Prefix, Infix,
Stacks - 3 Nour El-Kadri CSI Evaluating arithmetic expressions Stack-based algorithms are used for syntactical analysis (parsing). For example.
Prefix, Postfix, Infix Notation
Computer Science 112 Fundamentals of Programming II Applications of Stacks.
Stacks Chapter 21 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Arithmetic Expressions Infix form –operand operator operand 2+3 or a+b –Need precedence rules –May use parentheses 4*(3+5) or a*(b+c)
COSC 2006 Chapter 7 Stacks III
Joseph Lindo Abstract Data Types Sir Joseph Lindo University of the Cordilleras.
Arithmetic Expressions
Topic 15 Implementing and Using Stacks
CS 206 Introduction to Computer Science II 03 / 06 / 2009 Instructor: Michael Eckmann.
Stacks & Queues Infix Calculator CSC 172 SPRING 2002 LECTURE 5.
Infix to postfix conversion Process the tokens from a vector infixVect of tokens (strings) of an infix expression one by one When the token is an operand.
Stacks & Queues Infix Calculator CSC 172 SPRING 2004 LECTURE 13.
CS 206 Introduction to Computer Science II 10 / 17 / 2008 Instructor: Michael Eckmann.
Infix, Postfix, Prefix.
Reverse Polish Expressions Some general observations about what they are and how they relate to infix expressions. These 9 slides provide details about.
1 CSCD 326 Data Structures I Infix Expressions. 2 Infix Expressions Binary operators appear between operands: W - X / Y - Z Order of evaluation is determined.
Topic 15 Implementing and Using Stacks
CS 206 Introduction to Computer Science II 10 / 28 / 2009 Instructor: Michael Eckmann.
The Stack and Queue Types Lecture 10 Hartmut Kaiser
Data Structures Lecture : Stacks (Infix, Postfix and Prefix Expressions) Azhar Maqsood NUST Institute of Information Technology (NIIT)
Stack Applications.
CSC 205 Programming II Postfix Expressions. Recap: Stack Stack features Orderly linear structure Access from one side only – top item Stack operations.
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
(c) University of Washington20d-1 CSC 143 Java Applications of Trees.
Basic Data Structures Stacks. A collection of objects Objects can be inserted into or removed from the collection at one end (top) First-in-last-out.
Copyright © Curt Hill Stacks An Useful Abstract Data Type.
CHP-3 STACKS.
Reverse Polish Notation Written by J.J. Shepherd.
Prefix, Postfix, Infix Notation. Infix Notation  To add A, B, we write A+B  To multiply A, B, we write A*B  The operators ('+' and '*') go in between.
Stacks A stack is a linear data structure that can be accessed only at one of its ends for storing and retrieving data LIFO (Last In First Out) structure.
DATA STRUCTURES Application of Stack – Infix to Postfix conversion a Joshua Presentation.
CC 215 DATA STRUCTURES MORE ABOUT STACK APPLICATIONS Dr. Manal Helal - Fall 2014 Lecture 6 AASTMT Engineering and Technology College 1.
Applications of Stack Maitrayee Mukerji. Stacks Last In First Out (LIFO List) ◦ FILO? Insertions and Deletions from the same end called the Top Push(),
CSC 172 DATA STRUCTURES. A TALE OF TWO STRUCTURES.
BCA II Data Structure Using C
Review Use of Stack Introduction Stack in our life Stack Operations
Stacks Access is allowed only at one point of the structure, normally termed the top of the stack access to the most recently added item only Operations.
COMPSCI 107 Computer Science Fundamentals
Infix to postfix conversion
CSC 172 DATA STRUCTURES.
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Stack application: postponing data usage
Stacks – Calculator Application
Stacks – Calculator Application
Stacks – Calculator Application
PART II STACK APPLICATIONS
Stacks Chapter 5 Adapted from Pearson Education, Inc.
Stacks, Queues, and Deques
More About Stacks: Stack Applications
Lecture No.07 Data Structures Dr. Sohail Aslam
Infix to Postfix Conversion
Stacks and Queues 1.
Stacks – Calculator Application
Stack Applications Lecture 29 Thu, Apr 5, /23/2019
Infix to Postfix Conversion
CSC 143 Java Applications of Trees.
(Part 2) Infix, Prefix & Postfix
Stack.
Queue Applications Lecture 31 Tue, Apr 11, 2006.
Stack Applications Lecture 29 Thu, Apr 1, /29/2019 Stacks.
Queues Lecture 30 Fri, Apr 2, /3/2019 Queues.
More About Stacks: Stack Applications
17CS1102 DATA STRUCTURES © 2016 KL University – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS.
Chapter 7 (continued) © 2011 Pearson Addison-Wesley. All rights reserved.
Stacks A stack is an ordered set of elements, for which only the last element placed into the stack is accessible. The stack data type is also known as.
Presentation transcript:

Queue Applications Lecture 31 Mon, Apr 9, 2007

Infix Expression Evaluation An infix expression with one (binary) operator is written in the order: left-operand, operator, right-operand. Example: 3 + 4 2/23/2019 Queues

Disadvantages of Infix Notation Parentheses are often needed to indicate order of operation. Example: (3 + 4) * (5 + 6) Operators follow a precedence hierarchy. Example: 3 + 4 * 5 – 6 / 7 Operators have left or right associativity. Example: 100 – 50 – 10 – 5 – 1 2/23/2019 Queues

Infix Expression Evaluation To evaluate an infix expression, we first convert it to postfix. Then begin with an empty stack and an empty queue. Process the tokens from left to right according to the following rules. If the token is a number, Enqueue the token. If the token is a left parenthesis, Push the token onto the stack. 2/23/2019 Queues

Infix Expression Evaluation If the token is a right parenthesis, Pop tokens off the stack and enqueue them until a left parenthesis is popped. Discard the right and left parentheses. 2/23/2019 Queues

Infix Expression Evaluation If the token is an operator, Pop tokens off the stack and enqueue them until An operator of lower precedence is on top of the stack, or A left parenthesis is on top of the stack, or The stack is empty. Push the operator onto the stack. 2/23/2019 Queues

Infix Expression Evaluation After processing the last token Pop all tokens off the stack and enqueue them. The queue now contains the expression in post-fix notation. Process the queue as a post-fix expression. 2/23/2019 Queues

Example Convert the expression ((1 + 2)*3 – 4/(5 + 6 – 7*8))*9 7 from infix to postfix notation. 2/23/2019 Queues

Example Input token Stack Queue ( ( ( 1 + ( ( + 2 1 2 ) 1 2 + * ( * 3 1 2 + 3 – ( – 1 2 + 3 * 2/23/2019 Queues

Example Input token Stack Queue 4 ( – 1 2 + 3 * 4 / ( – / ( ( – / ( 5 1 2 + 3 * 4 5 + ( – / ( + 6 1 2 + 3 * 4 5 6 – ( – / ( – 1 2 + 3 * 4 5 6 + 7 1 2 + 3 * 4 5 6 + 7 * ( – / ( – * 2/23/2019 Queues

Example Input token Stack Queue 8 ( – / ( – * 1 2 + 3 * 4 5 6 + 7 8 ) 1 2 + 3 * 4 5 6 + 7 8 * – 1 2 + 3 * 4 5 6 + 7 8 * – / – * 9 1 2 + 3 * 4 5 6 + 7 8 * – / – 9 eof 1 2 + 3 * 4 5 6 + 7 8 * – / – 9 * 2/23/2019 Queues