Stacks and their Applications

Similar documents
Stack Applications. Lecture 27 Sections Robb T. Koether. Hampden-Sydney College. Wed, Mar 29, 2017

Stack Applications. Lecture 25 Sections Robb T. Koether. Hampden-Sydney College. Mon, Mar 30, 2015

Operators. Lecture 12 Section Robb T. Koether. Hampden-Sydney College. Fri, Feb 9, 2018

Binary Tree Implementation

Binary Tree Implementation

Abstract Data Types. Lecture 23 Section 7.1. Robb T. Koether. Hampden-Sydney College. Wed, Oct 24, 2012

STACKS AND QUEUES. Problem Solving with Computers-II

The Class Construct Part 1

The Class Construct Part 2

Array Lists. Lecture 15. Robb T. Koether. Hampden-Sydney College. Fri, Feb 16, 2018

Array Lists. Lecture 15. Robb T. Koether. Hampden-Sydney College. Mon, Feb 22, 2016

STACKS. A stack is defined in terms of its behavior. The common operations associated with a stack are as follows:

Scope and Parameter Passing

Friends and Unary Operators

Stacks. Chapter 5. Copyright 2012 by Pearson Education, Inc. All rights reserved

List Iterator Implementation

LR Parsing - Conflicts

while Loops Lecture 13 Sections Robb T. Koether Wed, Sep 26, 2018 Hampden-Sydney College

Scope and Parameter Passing

Stack and Its Implementation

The Stack and Queue Types

The Traveling Salesman Problem Nearest-Neighbor Algorithm

Binary Tree Applications

The x86 Instruction Set

[CS302-Data Structures] Homework 2: Stacks

-The Hacker's Dictionary. Friedrich L. Bauer German computer scientist who proposed "stack method of expression evaluation" in 1955.

Recursive Linked Lists

Stack Abstract Data Type

The Critical-Path Algorithm

Some Applications of Stack. Spring Semester 2007 Programming and Data Structure 1

Stacks. Chapter 5. Copyright 2012 by Pearson Education, Inc. All rights reserved

Minimal Spanning Trees

The x86 Architecture

Lecture Data Structure Stack

Dynamic Allocation of Memory

Implementing Linked Lists

Lecture 12 ADTs and Stacks

Formal Languages and Automata Theory, SS Project (due Week 14)

Linear Data Structure

The Traveling Salesman Problem Brute Force Method

Recursive Sequences. Lecture 24 Section 5.6. Robb T. Koether. Hampden-Sydney College. Wed, Feb 27, 2013

Containers: Stack. Jordi Cortadella and Jordi Petit Department of Computer Science

Recursive Sequences. Lecture 24 Section 5.6. Robb T. Koether. Hampden-Sydney College. Wed, Feb 26, 2014

Inheritance: The Fundamental Functions

March 13/2003 Jayakanth Srinivasan,

The string Class. Lecture 21 Sections 2.9, 3.9, Robb T. Koether. Wed, Oct 17, Hampden-Sydney College

Data Structure using C++ Lecture 04. Data Structures and algorithm analysis in C++ Chapter , 3.2, 3.2.1

Containers: Stack. The Stack ADT. The Stack ADT. The Stack ADT

Scheduling and Digraphs

Pointers. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Fri, Jan 18, 2013

Stacks Calculator Application. Alexandra Stefan

The Graphics Pipeline

Programming Languages

Recursive Descent Parsers

The x87 Floating-Point Unit

LR Parsing - The Items

09 STACK APPLICATION DATA STRUCTURES AND ALGORITHMS REVERSE POLISH NOTATION

The Model Stack. Lecture 8. Robb T. Koether. Hampden-Sydney College. Wed, Sep 6, 2017

Sampling Distribution Examples Sections 15.4, 15.5

Dynamic Allocation of Memory

EC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3

The Standard Template Library Classes

Pointers. Lecture 1 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 14, 2015

IV. Stacks. A. Introduction 1. Consider the 4 problems on pp (1) Model the discard pile in a card game. (2) Model a railroad switching yard

Recursion. Lecture 26 Sections , Robb T. Koether. Hampden-Sydney College. Mon, Apr 6, 2015

The Plurality-with-Elimination Method

Pointer Arithmetic. Lecture 4 Chapter 10. Robb T. Koether. Hampden-Sydney College. Wed, Jan 25, 2017

Stacks. Revised based on textbook author s notes.

Magnification and Minification

Stacks. stacks of dishes or trays in a cafeteria. Last In First Out discipline (LIFO)

Building the Abstract Syntax Trees

Ch. 18: ADTs: Stacks and Queues. Abstract Data Type

Linked Lists. Lecture 16 Sections Robb T. Koether. Hampden-Sydney College. Wed, Feb 22, 2017

Stack. 4. In Stack all Operations such as Insertion and Deletion are permitted at only one end. Size of the Stack 6. Maximum Value of Stack Top 5

Data Structures & Algorithm Analysis. Lecturer: Souad Alonazi

The Decreasing-Time Algorithm

The Pairwise-Comparison Method

Top of the Stack. Stack ADT

Data Structures Week #3. Stacks

Programming Languages

Top of the Stack. Stack ADT

Pointers. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Mon, Jan 20, 2014

PA3 Design Specification

An Introduction to Trees

Recognition of Tokens

Lecture 4: Stack Applications CS2504/CS4092 Algorithms and Linear Data Structures. Parentheses and Mathematical Expressions

SimpleCalc. which can be entered into a TI calculator, like the one on the right, like this:

Data Structures and Algorithms

The Constructors. Lecture 6 Sections Robb T. Koether. Hampden-Sydney College. Fri, Jan 26, 2018

Inheritance: The Fundamental Functions

The Graphics Pipeline

Abstract Data Types. Stack. January 26, 2018 Cinda Heeren / Geoffrey Tien 1

Solving Recursive Sequences by Iteration

The Constructors. Lecture 7 Sections Robb T. Koether. Hampden-Sydney College. Wed, Feb 1, 2017

CS 211. Project 5 Infix Expression Evaluation

Rotations and Translations

Function Usage. Lecture 15 Sections 6.3, 6.4. Robb T. Koether. Hampden-Sydney College. Mon, Oct 1, 2018

First Semester - Question Bank Department of Computer Science Advanced Data Structures and Algorithms...

Stacks Fall 2018 Margaret Reid-Miller

Infix to Postfix Conversion

Transcription:

Stacks and their Applications Lecture 23 Sections 18.1-18.2 Robb T. Koether Hampden-Sydney College Fri, Mar 16, 2018 Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 1 / 38

1 Stacks 2 The Stack Interface 3 Stack Applications Function Calls Infix, Postfix, and Prefix Notation Infix Expression Evaluation Postfix Expressions 4 Assignment Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 2 / 38

Outline 1 Stacks 2 The Stack Interface 3 Stack Applications Function Calls Infix, Postfix, and Prefix Notation Infix Expression Evaluation Postfix Expressions 4 Assignment Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 3 / 38

Stacks Definition Stack) A stack is a list that operates under the principle last in, first out LIFO). New elements are pushed onto the stack. Old elements are popped off the stack. To enforce the LIFO principle, we use a list and push and pop at the same end. Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 4 / 38

Outline 1 Stacks 2 The Stack Interface 3 Stack Applications Function Calls Infix, Postfix, and Prefix Notation Infix Expression Evaluation Postfix Expressions 4 Assignment Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 5 / 38

Stack Constructors Stack Constructors Stack); Stackconst Stack& s); Stack) constructs an empty stack. StackStack&) constructs a copy of the specified stack. Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 6 / 38

Stack Inspectors Stack Inspectors T top) const; int size) const; bool isempty) const; top) gets a copy of the element at the top of the stack but does not remove it). size) gets the number of elements in the stack. isempty) determines whether the stack is empty. Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 7 / 38

Stack Mutators Stack Mutators void pushconst T& value); T pop); void makeempty); push) pushes the specified value onto the top of the stack. pop) pops and returns the element off the top of the stack. makeempty) makes the stack empty. Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 8 / 38

Other Stack Member Functions Other Stack Member Functions bool isvalid) const; isvalid) determines whether the stack has a valid structure. Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 9 / 38

Other Stack Functions Other Stack Functions istream& operator>>istream& in, Stack& s); ostream& operator<<ostream& out, const Stack& s); operator>>) reads a Stack object from the input stream. operator<<) writes a Stack object to the output stream. Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 10 / 38

Implementation of Stacks Which push and pop functions should we use? pushfront) and popfront), or pushback) and popback). Choose a List class for which pushing and popping at one end will be efficient. Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 11 / 38

The Input Facilitator One must be careful when reading a stack. {10, 20, 30, 40, 50} As the values are read from left to right, they should be pushed onto the stack at one end or the other). Which end, left or right, is the top of the stack? It matters.) When we display the stack, it should look the same regardless of the kind of List we used. Do we need to write new input) and/or output) functions? Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 12 / 38

Outline 1 Stacks 2 The Stack Interface 3 Stack Applications Function Calls Infix, Postfix, and Prefix Notation Infix Expression Evaluation Postfix Expressions 4 Assignment Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 13 / 38

Outline 1 Stacks 2 The Stack Interface 3 Stack Applications Function Calls Infix, Postfix, and Prefix Notation Infix Expression Evaluation Postfix Expressions 4 Assignment Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 14 / 38

Handling Function Calls When a function is called, the program Pushes the values of the parameters. Pushes the address of the next instruction to which the function should return later). Allocates space on the stack for the local variables. Branches to the first line in the function. Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 15 / 38

Handling Function Calls The Stack Other Stuff Begin with the current stack Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 16 / 38

Handling Function Calls The Stack Other Stuff Function Parameters Push the function parameters Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 16 / 38

Handling Function Calls The Stack Other Stuff Function Parameters Return Address Push the return address Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 16 / 38

Handling Function Calls The Stack Other Stuff Function Parameters Return Address Local Variables Push the local variables Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 16 / 38

Handling Function Calls When a function returns, the program Pops the values of the local variables. Pops the return address and stores it in the IP register. Pops the parameters. The stack has now been returned to its previous state. Execution continues with the instruction in the IP register. Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 17 / 38

Handling Function Calls The Stack Other Stuff Function Parameters Return Address Pop the local variables Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 18 / 38

Handling Function Calls The Stack Other Stuff Function Parameters Pop the return address Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 18 / 38

Handling Function Calls The Stack Other Stuff Pop the function parameters Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 18 / 38

Outline 1 Stacks 2 The Stack Interface 3 Stack Applications Function Calls Infix, Postfix, and Prefix Notation Infix Expression Evaluation Postfix Expressions 4 Assignment Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 19 / 38

Infix Notation An infix expression is an arithmetic expression in which the binary operators are written in between the operands. For example, to add 3 and 4, we write 3 + 4. Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 20 / 38

Postfix Expressions In a postfix expression, the operator is written after the operands. For example, to add 3 and 4, we write 3 4 +. The infix expression 2 3 + 4 5 would be written as 2 3 4 5 + in postfix notation. Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 21 / 38

Prefix Expressions In a prefix expression, the operator is written before the operands. For example, to add 3 and 4, we write + 3 4. The infix expression 2 3 + 4 5 would be written as + 2 3 4 5 in prefix notation. Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 22 / 38

Outline 1 Stacks 2 The Stack Interface 3 Stack Applications Function Calls Infix, Postfix, and Prefix Notation Infix Expression Evaluation Postfix Expressions 4 Assignment Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 23 / 38

Fully Parenthesized Infix Expressions With infix expressions, the operations are not necessarily performed from left to right. Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 24 / 38

Fully Parenthesized Infix Expressions With infix expressions, the operations are not necessarily performed from left to right. Infix expressions may require parentheses to specify the order of operation. Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 24 / 38

Fully Parenthesized Infix Expressions With infix expressions, the operations are not necessarily performed from left to right. Infix expressions may require parentheses to specify the order of operation. Precedence and associativity rules allow us to omit some of the parentheses. Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 24 / 38

Fully Parenthesized Infix Expressions With infix expressions, the operations are not necessarily performed from left to right. Infix expressions may require parentheses to specify the order of operation. Precedence and associativity rules allow us to omit some of the parentheses. A fully parenthesized expression requires no precedence or associativity rules. Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 24 / 38

Fully Parenthesized Infix Expressions With infix expressions, the operations are not necessarily performed from left to right. Infix expressions may require parentheses to specify the order of operation. Precedence and associativity rules allow us to omit some of the parentheses. A fully parenthesized expression requires no precedence or associativity rules. In a fully parenthesized expression, there is a pair of parentheses for every operator. Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 24 / 38

Examples The expression 1 + 2 3 would be fully parenthesized as 1 + 2 3)). The expression 2 3 + 4/5 6 would be fully parenthesized as 2 3) + 4/5)) 6). Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 25 / 38

Infix Expression Evaluation We may use a pair of stacks to evaluate a fully parenthesized infix expression. The expression contains four types of token: Left parenthesis Right parenthesis ) Number, e.g., 123 Operator +,,, / Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 26 / 38

Infix Expression Evaluation To evaluate the expression we need a stack of numbers and a stack of operators. Read the tokens from left to right and process them as follows: Token Left parenthesis Number Operator Right Parenthesis Action No action Push the number onto the number stack Push the operator onto the operator stack 1. Pop two numbers off the number stack 2. Pop one operator off the operator stack 3. Perform the operation on the numbers 4. Push the result onto the number stack Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 27 / 38

Example Use the algorithm to evaluate the expression 2 5) + 6/3)) 8) Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 28 / 38

Example Robb T. Koether Hampden-Sydney College) Stacks and caption their Applications Fri, Mar 16, 2018 29 / 38 Token Number Stack Operator Stack Begin with an empty stack

Robb T. Koether Hampden-Sydney College) Stacks and caption their Applications Fri, Mar 16, 2018 29 / 38 Example Token Number Stack Operator Stack 2 5) + 6/3)) 8)

Robb T. Koether Hampden-Sydney College) Stacks and caption their Applications Fri, Mar 16, 2018 29 / 38 Example Token Number Stack Operator Stack 2 5) + 6/3)) 8)

Robb T. Koether Hampden-Sydney College) Stacks and caption their Applications Fri, Mar 16, 2018 29 / 38 Example Token Number Stack Operator Stack 2 5) + 6/3)) 8)

Robb T. Koether Hampden-Sydney College) Stacks and caption their Applications Fri, Mar 16, 2018 29 / 38 Example Token Number Stack Operator Stack 2 2 2 5) + 6/3)) 8)

Robb T. Koether Hampden-Sydney College) Stacks and caption their Applications Fri, Mar 16, 2018 29 / 38 Example Token Number Stack Operator Stack 2 2 2 2 5) + 6/3)) 8)

Robb T. Koether Hampden-Sydney College) Stacks and caption their Applications Fri, Mar 16, 2018 29 / 38 Example Token Number Stack Operator Stack 2 2 2 5 2 5 2 5) + 6/3)) 8)

Robb T. Koether Hampden-Sydney College) Stacks and caption their Applications Fri, Mar 16, 2018 29 / 38 Example Token Number Stack Operator Stack 2 2 2 5 2 5 ) 10 2 5) + 6/3)) 8)

Robb T. Koether Hampden-Sydney College) Stacks and caption their Applications Fri, Mar 16, 2018 29 / 38 Example Token Number Stack Operator Stack 2 2 2 5 2 5 ) 10 + 10 + 2 5) + 6/3)) 8)

Robb T. Koether Hampden-Sydney College) Stacks and caption their Applications Fri, Mar 16, 2018 29 / 38 Example Token Number Stack Operator Stack 2 2 2 5 2 5 ) 10 + 10 + 10 + 2 5) + 6/3)) 8)

Robb T. Koether Hampden-Sydney College) Stacks and caption their Applications Fri, Mar 16, 2018 29 / 38 Example Token Number Stack Operator Stack 2 2 2 5 2 5 ) 10 + 10 + 10 + 6 10 6 + 2 5) + 6/3)) 8)

Robb T. Koether Hampden-Sydney College) Stacks and caption their Applications Fri, Mar 16, 2018 29 / 38 Example Token Number Stack Operator Stack 2 2 2 5 2 5 ) 10 + 10 + 10 + 6 10 6 + / 10 6 + / 2 5) + 6/3)) 8)

Robb T. Koether Hampden-Sydney College) Stacks and caption their Applications Fri, Mar 16, 2018 29 / 38 Example Token Number Stack Operator Stack 2 2 2 5 2 5 ) 10 + 10 + 10 + 6 10 6 + / 10 6 + / 3 10 6 3 + / 2 5) + 6/3)) 8)

Robb T. Koether Hampden-Sydney College) Stacks and caption their Applications Fri, Mar 16, 2018 29 / 38 Example Token Number Stack Operator Stack 2 2 2 5 2 5 ) 10 + 10 + 10 + 6 10 6 + / 10 6 + / 3 10 6 3 + / ) 10 2 + 2 5) + 6/3)) 8)

Robb T. Koether Hampden-Sydney College) Stacks and caption their Applications Fri, Mar 16, 2018 29 / 38 Example Token Number Stack Operator Stack 2 2 2 5 2 5 ) 10 + 10 + 10 + 6 10 6 + / 10 6 + / 3 10 6 3 + / ) 10 2 + ) 12 2 5) + 6/3)) 8)

Robb T. Koether Hampden-Sydney College) Stacks and caption their Applications Fri, Mar 16, 2018 29 / 38 Example Token Number Stack Operator Stack 2 2 2 5 2 5 ) 10 + 10 + 10 + 6 10 6 + / 10 6 + / 3 10 6 3 + / ) 10 2 + ) 12 12 2 5) + 6/3)) 8)

Robb T. Koether Hampden-Sydney College) Stacks and caption their Applications Fri, Mar 16, 2018 29 / 38 Example Token Number Stack Operator Stack 2 2 2 5 2 5 ) 10 + 10 + 10 + 6 10 6 + / 10 6 + / 3 10 6 3 + / ) 10 2 + ) 12 12 8 12 8 2 5) + 6/3)) 8)

Robb T. Koether Hampden-Sydney College) Stacks and caption their Applications Fri, Mar 16, 2018 29 / 38 Example Token Number Stack Operator Stack 2 2 2 5 2 5 ) 10 + 10 + 10 + 6 10 6 + / 10 6 + / 3 10 6 3 + / ) 10 2 + ) 12 12 8 12 8 ) 4 2 5) + 6/3)) 8)

Infix Expression Evaluation Run the program InfixEvalFullParen.cpp. Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 30 / 38

Outline 1 Stacks 2 The Stack Interface 3 Stack Applications Function Calls Infix, Postfix, and Prefix Notation Infix Expression Evaluation Postfix Expressions 4 Assignment Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 31 / 38

Postfix Expression Evaluation Example Postfix Expressions) Expression: 3 4 + 5 6 +. Left operand of is 3 4 +. Right operand of is 5 6 +. In postfix expressions, parentheses are never needed! Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 32 / 38

Postfix Expression Evaluation To evaluate a postfix expression we need a stack of numbers. Read the tokens from left to right and process them as follows: Token Number Operator Action Push the number onto the number stack 1. Pop two numbers off the number stack 2. Pop one operator off the operator stack 3. Perform the operation on the numbers 4. Push the result onto the number stack Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 33 / 38

Postfix Expression Evaluation Example Postfix Expressions) The fully parenthesized infix expression 2 5) + 6/3)) 8) can be written as 2 5 + 6/3 8 As a postfix expression, it is 2 5 6 3 / + 8 Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 34 / 38

Example Token 2 2 Number Stack 2 5 6 3 / + 8 Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 35 / 38

Example Token 2 2 5 2 5 Number Stack 2 5 6 3 / + 8 Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 35 / 38

Example Token 2 2 5 2 5 10 Number Stack 2 5 6 3 / + 8 Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 35 / 38

Example Token 2 2 5 2 5 10 6 10 6 Number Stack 2 5 6 3 / + 8 Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 35 / 38

Example Token Number Stack 2 2 5 2 5 10 6 10 6 3 10 6 3 2 5 6 3 / + 8 Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 35 / 38

Example Token Number Stack 2 2 5 2 5 10 6 10 6 3 10 6 3 / 10 2 2 5 6 3 / + 8 Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 35 / 38

Example Token Number Stack 2 2 5 2 5 10 6 10 6 3 10 6 3 / 10 2 + 12 2 5 6 3 / + 8 Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 35 / 38

Example Token Number Stack 2 2 5 2 5 10 6 10 6 3 10 6 3 / 10 2 + 12 8 12 8 2 5 6 3 / + 8 Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 35 / 38

Example Token Number Stack 2 2 5 2 5 10 6 10 6 3 10 6 3 / 10 2 + 12 8 12 8 4 2 5 6 3 / + 8 Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 35 / 38

Postfix Expression Evaluation Run the program PostfixEvaluator.cpp. Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 36 / 38

Outline 1 Stacks 2 The Stack Interface 3 Stack Applications Function Calls Infix, Postfix, and Prefix Notation Infix Expression Evaluation Postfix Expressions 4 Assignment Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 37 / 38

Assignment Assignment Read Sections 18.1-18.2, 18.7-18.8. Robb T. Koether Hampden-Sydney College) Stacks and their Applications Fri, Mar 16, 2018 38 / 38