1_stack - Stacks and Queues ! Abstract ! Stacks Data Types...

Info iconThis preview shows pages 1–18. Sign up to view the full content.

View Full Document Right Arrow Icon
Stacks and Queues
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
! Abstract Data Types ! Stacks ! Queues ! Priority Queues September 2004 John Edgar 2
Background image of page 2
September 2004 John Edgar 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
! Reverse Polish Notation (RPN) ! Also known as postfix notation ! A mathematical notation Where every operator follows its operands ! Invented by Jan Ł ukasiewicz in 1920 ! Example ! Infix: 5 + ((1 + 2) * 4) 3 ! RPN: 5 1 2 + 4 * + 3 – September 2004 John Edgar 4
Background image of page 4
! 5 1 2 + 4 * + 3 – September 2004 John Edgar 5 5 store 5 store 1 store 2 Apply + to the last two operands 1 2
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
! 5 1 2 + 4 * + 3 – September 2004 John Edgar 6 5 store 5 store 1 store 2 Apply + to the last two operands store result store 4 Apply * to the last two operands 3 4
Background image of page 6
! 5 1 2 + 4 * + 3 – September 2004 John Edgar 7 5 store 5 store 1 store 2 Apply + to the last two operands store result store 4 Apply * to the last two operands store result 12 Apply + to the last two operands
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
! 5 1 2 + 4 * + 3 – September 2004 John Edgar 8 store 5 store 1 store 2 Apply + to the last two operands store result store 4 Apply * to the last two operands store result store 3 Apply + to the last two operands store result 3 Apply - to the last two operands 17
Background image of page 8
! 5 1 2 + 4 * + 3 – September 2004 John Edgar 9 store 5 store 1 store 2 Apply + to the last two operands store result store 4 Apply * to the last two operands store result store 3 Apply + to the last two operands store result Apply - to the last two operands 14 store result retrieve answer
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
! What are the storage properties of the data structure that we used? ! Specifically how are items inserted and removed? ! The last item to be entered is the first item to be removed ! Known as LIFO (Last In First Out) ! A stack September 2004 John Edgar 10
Background image of page 10
September 2004 John Edgar 11
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
! A stack only allows items to be inserted and removed at one end ! We call this end the top of the stack ! The other end is called the bottom ! Access to other items in the stack is not allowed September 2004 John Edgar 12
Background image of page 12
! A stack can be used to naturally store data for postfix notation ! Operands are stored at the top of the stack ! And removed from the top of the stack ! Notice that we have not (yet) discussed how a stack should be implemented ! Just what it does ! An example of an Abstract Data Type September 2004 John Edgar 13
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
September 2004 John Edgar 14
Background image of page 14
! A collection of data ! Describes the data but not how it is stored ! Set of operations on the data ! Describes precisely what effect the operations have on the data but ! Does not specify how operations are carried out ! An ADT is not a data structure September 2004 John Edgar 15
Background image of page 15

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
! The term concrete data type is usually used in contrast with an ADT ! An ADT is a collection of data and a set of operations on the data ! A concrete data type is an implementation of an ADT using a data structure ! A construct that is defined in a programming language to store a collection of data September 2004 John Edgar 16
Background image of page 16
!
Background image of page 17

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 18
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 114

1_stack - Stacks and Queues ! Abstract ! Stacks Data Types...

This preview shows document pages 1 - 18. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online